ElijahLoop 0 Posted February 12 Share Posted February 12 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 post Share on other sites
requinix 983 Posted February 12 Share Posted February 12 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 post Share on other sites
guymclarenza 2 Posted February 12 Share Posted February 12 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 post Share on other sites
Strider64 19 Posted February 12 Share Posted February 12 (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 by Strider64 Quote Link to post Share on other sites
Phi11W 13 Posted February 15 Share Posted February 15 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 post Share on other sites
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.