8

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 ?

1

2 Answers 2

10

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 :)

0
4

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.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.