model logic clarification - card model

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

model logic clarification - card model

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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?
(#10850)
Post Reply