Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Which are the three main categories of design patterns?

There are three basic classifications of patterns Creational, Structural, and Behavioral patterns. Creational Patterns Abstract Factory:- Creates an instance of several families of classes Builder: - Separates object construction from its representation Factory Method:- Creates an instance of several derived classes Prototype:- A fully initialized instance to be copied or cloned Singleton:- A class in which only a single instance can exist Note: - The best way to remember Creational pattern is by remembering ABFPS (Abraham Became First President of States). Structural Patterns Adapter:-Match interfaces of different classes . Bridge:-Separates an objects abstraction from its implementation. Composite:-A tree structure of simple and composite objects. Decorator:-Add responsibilities to objects dynamically. Faade:-A single class that represents an entire subsystem. Flyweight:-A fine-grained instance used for efficient sharing. Proxy:-An object representing another object. Behavioral patterns Mediator:-Defines simplified communication between classes. Memento:-Capture and restore an object's internal state. Interpreter:- A way to include language elements in a program. Iterator:-Sequentially access the elements of a collection. Chain of Resp: - A way of passing a request between a chain of objects. Command:-Encapsulate a command request as an object. State:-Alter an object's behavior when its state changes.

Strategy:-Encapsulates an algorithm inside a class. Observer: - A way of notifying change to a number of classes. Template Method:-Defer the exact steps of an algorithm to a subclass. Visitor:-Defines a new operation to a class without change.

Factory Pattern Factory pattern is one of the types of creational patterns. You can make out from the name factory itself its meant to construct and create something. Can you explain abstract factory pattern? Abstract factory expands on the basic factory pattern. Abstract factory helps us to unite similar factory pattern classes in to one unified interface. So basically all the common factory patterns now inherit from a common abstract factory class which unifies them in a common class Can you explain builder pattern? Builder pattern helps us to separate the construction of a complex object from its representation so that the same construction process can create different representations. Builder pattern is useful when the construction of the object is very complex Can you explain prototype pattern? Prototype pattern falls in the section of creational pattern. It gives us a way to create new objects from the existing instance of the object. In one sentence we clone the existing object with its data.

Template Pattern A Template is a way for use to define the skeleton of an algorithm in an abstract class. The skeleton for our algorithm is defined within a final method, so the outline cannot change. Singleton classes Singleton class is a class that will only have one instance of the class. Strategy Pattern We have taken the behavior of the object and placed it in an abstract class and in an interface. We then took the behavior AWAY from the implementation. The main thing to keep in mind when coding these is think about your object and ask what behavior is static and what behavior is dynamic? Take what is dynamic and encapsulate it and take it away from your main object. Amount class the strategy to calculate the amounts is in different classes Decoration Pattern It is extremely similar except for the fact that it not just allows you to swap out implementation at run time, but they allow you to build ON TOP of the behavior of your components. The way it works is a base class with a specific behavior. Then our decorator will be a class that we will use to change that behavior by extending the base class, as well as having that base class as a property on the component. In essence, the decorator extends and wraps the base class. Text class has a format function and the TextDecorator extends the Text class to provide various decorations like caps lowercase Composite The Composite pattern is useful when individual objects as well as aggregates of those objects are to be treated uniformly. Shape has a draw method and every class inheriting from shape must implement this method. State The state pattern, which closely resembles Strategy Pattern, is a behavioral software design pattern, also known as the objects for states pattern. This pattern is used in computer programming to represent the state of an object. This is a clean way for an object to partially change its type at runtime. Cursor changes its states based on different tasks. The Builder Pattern In Builder Pattern the user is given the choice to create the type of object he wants but the construction process is the same. We consider an example - suppose you went to buy a car. First you will choose the model of the car and then its color and you consider its price that whether its feasible for you or not. If

you want some extra luxuries in the car you will note them down as well and in the end you will place the order. Now you are isolated with the manufacturing process. You are not bothered by the manufacturing process. Its the duty of the company because they have the assembly plant, which is programmed to manufacture cars of the model you choose and the manufacturing process is the same for a specified model of car. In Builder, the client instructs the builder class how to create the object and then asks it for the result. How the class is put together is up to the Builder class. Factory A What kind of infrastructure have you gotten into the trenches and really gotten to know well? Here expect a laundry list of any kind of environmental setting but this may be important as if the person will be designing web applications and all they have ever done in embedded systems, you may have an initial hurdle of how well does this person know about web stuff .

You might also like