Separating Db from business with Inherited classes using multiple views
Posted
by
catalinux
on Programmers
See other posts from Programmers
or by catalinux
Published on 2013-10-28T14:14:01Z
Indexed on
2013/10/28
16:14 UTC
Read the original article
Hit count: 147
I have a software that has a car model that will be used in different views (listing, ads, detail page, carousel, up sell widget,etc).
class CarModel extends DbModel{
}
I look for a "nice way" (a combination of flexible, easy to maintain,etc) to have this used in views.
I'm thinking at two different ways
Having object views for each context
CarViewBase{ var car;// of type CarModel function constructor(args){ //will instantienta internal variable car based on args } function getThumb(){ } function getTitle(){ } } CarListingView extends CarViewBase{ function getListing(){ } } CarAdsView extends CarViewBase{ //the busines rule changes for ads widget function getThumb(){ } }
Extending directly the CarModel
The challenges comes when My Car Model might need an abstract factory. Let's say I have a field on my car object that states the type of the car : a truck, or a bike, or van. How would affect that my object view? Let's say that getTitle() rule would be different for each type of it.
How would you do it?
© Programmers or respective owner