Jump to content

How to format the method correctly?


Recommended Posts

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?

Link to post
Share on other sites

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.

Link to post
Share on other sites

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? ";
    }
}

 

Link to post
Share on other sites
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 by Strider64
Link to post
Share on other sites
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.

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.