ElijahLoop Posted February 12, 2021 Share Posted February 12, 2021 Hello everyone. I'm just learning programming. I have a class: class DbBox extends BoxAbstract { public function save() { } public function load() { } } This class has two methods, Load and Save. How to format them correctly so that they can save data to a file? Quote Link to comment https://forums.phpfreaks.com/topic/312135-how-to-format-the-method-correctly/ Share on other sites More sharing options...
requinix Posted February 12, 2021 Share Posted February 12, 2021 That's a really, really, really vague question. You're going to have to be a lot more precise about what this class is and what you're supposed to do with it. Quote Link to comment https://forums.phpfreaks.com/topic/312135-how-to-format-the-method-correctly/#findComment-1584407 Share on other sites More sharing options...
guymclarenza Posted February 12, 2021 Share Posted February 12, 2021 Neither of those functions has any options, what must they do class DbBox extends BoxAbstract { public function save() { echo "What must I save? "; } public function load() { echo "What must I load? "; } } Quote Link to comment https://forums.phpfreaks.com/topic/312135-how-to-format-the-method-correctly/#findComment-1584417 Share on other sites More sharing options...
Strider64 Posted February 12, 2021 Share Posted February 12, 2021 (edited) 26 minutes ago, guymclarenza said: Neither of those functions has any options, what must they do class DbBox extends BoxAbstract { public function save() { echo "What must I save? "; } public function load() { echo "What must I load? "; } } The methods/functions in the DbBox class to me is redundant unless you are going to override them, but like requinix stated "really, really, really vague question" to help with. I use the Active Record Design Pattern and those two classes would just be silly to me. Edited February 12, 2021 by Strider64 Quote Link to comment https://forums.phpfreaks.com/topic/312135-how-to-format-the-method-correctly/#findComment-1584419 Share on other sites More sharing options...
Phi11W Posted February 15, 2021 Share Posted February 15, 2021 On 2/12/2021 at 5:28 AM, ElijahLoop said: How to format them correctly so that they can save data to a file? Which file? Would you expect both the load() and save() method [of this subclass] to all the work to find out which file they needed to work with? No. What might be more "normal" would be to tell the object which file is should "save" itself to, i.e. you would pass the load() and save() methods the path to the target file. But then you have another problem ... This is a Box. A Musical Box, wound up and ready to ... no; that's a different story. This is a Box. It will be one of many Boxes and each of these will need to load() and save() themselves to/from somewhere (having one file per box might be OK, but could make for a lot of files!) A typical pattern I've seen to handle this is to pass each method something that it can read from or write to - a file stream is commonplace, but it really depends on how you intend to store your data ab out each box. Regards, Phill W. Quote Link to comment https://forums.phpfreaks.com/topic/312135-how-to-format-the-method-correctly/#findComment-1584483 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.