I recently complained (i.e. ranted) on the topic over at
http://blog.astrumfutura.com/archives/373-The-M-in-MVC-Why-Models-are-Misunderstood-and-Unappreciated.html
I generally prefer to avoid the inherited-from route. It's appropriate if
all you're doing is data access (not the real use of a Model) but it
tightens the coupling between your Models and the underlying framework.
Ideally Models are unaware of the framework, the acid test being able to
quickly port them from one framework to another with little to no change.
The has-a relationship works much better and tends to be more suitable for
web applications which don't require or need a huge amount of modelling.
Since it's outside the Model inheritance tree and included by composition
instead (composition over inheritance!), it also makes it simple to Mock
when performing testing. Quite useful if you're designing a Model and
pushing TO the database level, rather than the common designing Models FROM
an existing database schema.
Best regards,
Paddy
keith Pope-4 wrote:
>
> Yep:
>
> Domain Driven Design - Eric Evans - Very good book!
>
> http://www.amazon.co.uk/Domain-driven-Design-Tackling-Complexity-Software/dp/0321125215/ref=sr_1_1?ie=UTF8&s=books&qid=1228820157&sr=8-1
>
> Patterns of Enterprise Application Architecture - Martin Fowler - Also
> very good
>
> http://www.amazon.co.uk/Enterprise-Application-Architecture-Addison-Wesley-signature/dp/0321127420/ref=sr_1_8?ie=UTF8&s=books&qid=1228820157&sr=8-8
>
> The whole Addison Wesley signature series is very good.
>
> I have the beginnings of a example application for a book I am
> writing, its a work in progress but you are welcome to the code if you
> want, this uses the has-a method as the Domain Model was too complex
> for my requirements.
>
>
> 2008/12/9 Paul Court <paul@pmcnetworks.co.uk>:
>>
>> On 9 Dec 2008, at 10:23, keith Pope wrote:
>>>
>>> 3) Use a pure OO Domain Model
>>> This is where you have a totally clean domain layer, this means that
>>> your models do not know about any database/etc code. To achieve this
>>> you probably would be looking at implementing the Repository and Unit
>>> of Work patterns plus others.
>>
>> Do you have any good books or resources you can recommend for more
>> information on those patterns?
>>
>>
>>
>
>
>
> --
> ----------------------------------------------------------------------
> [MuTe]
> ----------------------------------------------------------------------
>
>
-----
Pádraic Brady
http://blog.astrumfutura.com
http://www.patternsforphp.com
OpenID Europe Foundation - Irish Representative
--
View this message in context: http://www.nabble.com/Another-Model-Design-Thread-tp20909700p20918043.html
Sent from the Zend MVC mailing list archive at Nabble.com.
没有评论:
发表评论