samedi 26 mai 2018

ECB pattern (Entity,Control,Boundary) implementation

I'm learning about the ECB pattern. I've understood the concept of this pattern but i'm not sure about its implementation. I'm going to write a simple example: I supposed to need a software which manages the customers of a shop. The customers are stored on a generic database. Accoding to the ECB pattern i need to have the following classes

1)Customer which represents the entity, with its attributes (name,surname,birthDate etc..)

2)CustomerWindow which represents the boundary, with some labels, textfields, buttons and a table to show customers

3)CustomerController which represents the logic with some methods (insert,delete etc...)

I should add also a CustomerDAO (implementing an interface, but my question is not about DAO) which manages the access to the database. I would like to know the way this classes interact each other. For example, supposing the insertion of a new customer, i suppose they interact like this:

1)The CustomerWindow "collects" the data written inside the textFields (name,surname ecc) and calls the method insert(String ....) of the CustomerController.

2)The CustomerController check if all data are ok (for example empty fields or format error). If they are ok, create a new Customer with that data and calls the method insert(Customer c) of the CustomerDAO.

3)The CustomerDao provide to insert the customer into the database

Obviously some of this operations could throw some exceptions but i think it's not important for this example, supposing inserted data are all valid. Is this the way the ECB pattern works? If not, how it works?

I have a last question: Some of this classes should be static or i need to declare an instance of each of them? For example i think the CustomerController and the Customer DAO can be static. The CustomeWindows calls the CustomerController.insert(...) method which eventually calls the CustomerDAO.insert(...) method (so i don't need to create a new CustomerController() or a new CustomerDAO(). Is it right?

I hope my english is pretty understandable. Please tell me if i've not been clear about something. Thank you all ;)

P.s. if you prefer i can write a code example

Aucun commentaire:

Enregistrer un commentaire