Page 1 of 1

model logic clarification - card model

Posted: Thu Jan 11, 2007 4:38 am
by raghavan20
let me explain with an example.

i have a credit card object and it has an associated address object which is considered as invoice address.

Code: Select all

business rules now:
adding card: add new card row and address row

editing card: update card and address rows

deleting card: delete card and address rows

view card: get card and address rows

now i have doubts regarding implementation of model logic and currently i can think of two ways of doing it.

1. we can have two models, cardModel and Address Model. When add/edit/delete/get card is called, first cardModel does the operation called and cardModel calls the same operation in AddressModel. this means more logic is done is done in Model of MVC.

2. we can have two models, cardModel and Address Model. Now, the card model is not aware of address model and it does not anyway interact with address model.
now, for example card is edited, update method of CardModel and update method of AddressModel are called by controller logic. this means logic is implemented in Controller of MVC.

i would like to know which one is better or suggest me any better method available to implement business logic related to the card operations that include address.


Thanks to all.

Posted: Thu Jan 11, 2007 6:28 am
by timvw

Posted: Thu Jan 11, 2007 3:39 pm
by Christopher
I don't think there is a clear "better way" between two separate Models and one compositing the other. However you may want to think of a third option if you use both the Card and Address Models separately in you code (because it is use cases that really matter). If you do then you might want to create a CardAndAddress class that composites both and provides a cleaner interface. The question is: do you have one, two or three use cases?