Posts

Showing posts with the label Design Pattern

Prototype

Why Prototype : Need to duplicate objects with different dynamic types Prototype is particularly useful with static languages like C++, where classes are not objects, and little or no type information is available at run-time. Benefits: 1.        Adding and removing products at run-time. 2.        Specifying new objects by varying values 3.        Specifying new objects by varying structure. 4.        Reduced subclassing. 5.        Configuring an application with classes dynamically. Difficulty: The implementation of clone operation: especially when their internals include objects that don't support copying or have circular references. Implementation Solutions: -           Provide a polymorphic method that returns an instance of the same type as the object on whi...

Factory Pattern

Definition Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses. Application Use the Factory Method pattern when · a class can't anticipate the class of objects it must create . · a class wants its subclasses to specify the objects it creates. · classes delegate responsibility to one of several helper subclasses, and you want to localize the knowledge of which helper subclass is the delegate. Implementation 1.        Two major varieties. The two main variations of the Factory Method pattern are (1) the case when the Creator class is an abstract class and does not provide an implementation for the factory method it declares, and (2) the case when the Creator is a concrete class and provides a default implementation for the factory method . 2.        Parameterized factory methods . Another variati...

Design Pattern

Design Pattern a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into source or machine code. It is a description or template for how to solve a problem that can be used in many different situations.   Object-oriented design patterns typically show relationships and interactions between classes or objects , without specifying the final application classes or objects that are involved. Patterns that imply object-orientation or more generally mutable state, are not as applicable in functional programming languages. Creational Design Pattern Singleton:   Ensure a class has only one instance, and provide a global point of access to it. Factory Method:  create a related type polymorphically Prototype:  allows polymorphic duplication of heterogeneous types Behavioral Design Pattern Visitor:   Repr...