I'm using PHP, and the Kohana framework, but that should be peripheral to this question.
I want to instantiate an object that has a couple related child objects, which in turn have some optional child objects that will be created.
I am new to OOP, and am trying to model the creation and management of this process. I would like the process to be recoverable if a user doesn't finish it in one session, so I'm expecting to be able to serialize the object and pull it from the database.
My general direction so far:
From an admin panel select a link th开发者_开发百科at reads www.example.com/create?new_process=true
That get request initializes the Creation_Management object.
Calls from the controller to the Creation_Management object:
$form_name = $creation_management_instance->which_form_to_render();
$this->view->set_file($file_name);
The cycle then continues, with forms coming in and objects being completed until the process is done.
Is there a good way to structure this situation?
Let me know if I can be more clear anywhere.
Well I don't know about the design pattern but it seems that you create a form and then depending upon certain conditions create the form's children.
Ideally, you would want to encapsulate the conditional creation of the children in the parent form. So pass your conditional parameters to the main form and that will decide which children it needs to construct and so on.
You will then need to serialize only one object (the main form), and the children will follow :)
Hope I got your use case right.
精彩评论