使用原型图案 [英] Use prototype pattern or not

查看:150
本文介绍了使用原型图案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题。我需要创造一些与产品有关的事情。现在我可以说7种不同类型的产品。有些是其他的亚型,例如

 汽车
- Vans
- 汽油
- 柴油
- 城市
- 掀背车
- 沙龙
- 庄园
- 汽油
- 柴油

现在,为了争论,我所有的城市,两厢车和轿车都是混合动力/燃气/不管什么,我不打算出售汽油和柴油。然而,有可能在将来有时候会有汽油和柴油轿车,但不像我将要有20多种类型的产品。如果要上去,我可能会有2-3种以上的类型。



从我所了解的原型模式可能是一个好的,因为我将能够避免重复, >汽油和汽油 - >汽油...但是再次Van车将具有不同于城市汽车的特点最大加载尺寸。



我一直在阅读广泛的设计模式,有一件事我记得肯定是不要使用模式,当你不需要它。现在的问题是 - 我需要吗?



谢谢!

解决方案

p>装饰图案可能是使用最直接的一个,并且是一个很好的扩展具体对象的功能和/或特征。



这里是一些阅读:头号设计模式 - CH3 pdf



FYI,夫妻必须有学习和参考设计模式,无论您选择的语言如何:



1 )首先设计模式



2)企业模式应用架构



3)



和网站:



1) DoFactory



2) StackOverflow设计模式Newbie



还有其他几个,我必须挖掘他们。


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:

1) Head First Design Patterns

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆