使用原型图案 [英] Use prototype pattern or not
问题描述
汽车
- Vans
- 汽油
- 柴油
- 城市
- 掀背车
- 沙龙
- 庄园
- 汽油
- 柴油
现在,为了争论,我所有的城市,两厢车和轿车都是混合动力/燃气/不管什么,我不打算出售汽油和柴油。然而,有可能在将来有时候会有汽油和柴油轿车,但不像我将要有20多种类型的产品。如果要上去,我可能会有2-3种以上的类型。
从我所了解的原型模式
可能是一个好的,因为我将能够避免重复, >汽油和汽油 - >汽油...但是再次Van车将具有不同于城市汽车的特点最大加载尺寸。
我一直在阅读广泛的设计模式,有一件事我记得肯定是不要使用模式,当你不需要它。现在的问题是 - 我需要吗?
谢谢!
p>装饰图案可能是使用最直接的一个,并且是一个很好的扩展具体对象的功能和/或特征。
这里是一些阅读:头号设计模式 - CH3 pdf
FYI,夫妻必须有学习和参考设计模式,无论您选择的语言如何:
1 )首先设计模式
2)企业模式应用架构
和网站:
1) DoFactory
还有其他几个,我必须挖掘他们。
I have a question. I need to create a little thing to do with products. Now I can have say 7 different types of products. Some are subtypes of others e.g.
Cars
- Vans
- petrol
- diesel
- City
- Hatchback
- Saloon
- Estate
- petrol
- diesel
Now, for the sake of the argument all my City, Hatchback and Saloon cars are hybrid/gas/whatever and I do not plan to sell petrol and diesel ones. However there is a possibility that I may have petrol and diesel saloon cars sometime in the future, but it's not like I am going to have 20+ types of products. If it is going to go up I will have probably 2-3 more types.
From what I understand Prototype Pattern
may be good one here for I will be able to avoid duplication between estate->petrol and van->petrol ... but then again Van cars will have different characteristics than say city car e.g. maximum loading dimensions.
I have been reading extensively about design patterns and one thing I remember for certain is not to use pattern when you don't need it. Now the question is - do I need it?
Thanks!
The Decorator Pattern is probably the most straight forward one to use and would be a good one to extend concrete objects functionality and/or characteristics.
Here is some light reading: Head First Design Patterns - CH3 pdf
FYI, couple must have's for learning and referencing design patterns regardless your language of choice:
2) Patterns for Enterprise Application Architecture
3) Design Patterns: Elements of Reusable Object-Oriented Software
And sites:
1) DoFactory
2) StackOverflow Design Patterns Newbie
There are a few others, I'll have to dig them up.
这篇关于使用原型图案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!