I am learning Design Patterns. Today I'm reading about Prototype DP and found that it's used for cloning an object. Since we have an ICloneable interface in .Net, do we still开发者_高级运维 need the Prototype DP ? Or does ICloneable
implement the Prototype DP? Any guidelines for choosing between the two ?
By implementing just an interface like ICloneable
doesn't mean you're following a pattern, all depends in the intent you're trying to achieve. This is somewhat philosophical if you will, but I just want to be sure to stress this. Patterns have forces and intents, and by definition is a general solution for a common problem.
In this particular example, yes, implementing correctly the interface can lead you to the intent of the pattern, in fact the wikipedia article uses the ICloneable
interface for its exameple written in Java : http://en.wikipedia.org/wiki/Prototype_pattern.
Of course you can use another approach, using another interface of yours, is not a requirement for the pattern to use the ICloneable
interface.
Hope this helps and welcome to the world of patterns :)
Design patterns are not something that are inherent in a language, but they are a common solution to a general problem. They are a concept and can be implemented in many different ways and many different languages.
精彩评论