There are two types of cloning for prototype patterns. One is the shallow cloning which you have just read in the first question. In shallow copy only that object is cloned, any objects containing in that object is not cloned. For instance consider the figure ‘Deep cloning in action’ we have a customer class and we have an address class aggregated inside the customer class. ‘MemberWiseClone’ will only clone the customer class ‘ClsCustomer’ but not the ‘ClsAddress’ class. So we added the ‘MemberWiseClone’ function in the address class also. Now when we call the ‘getClone’ function we call the parent cloning function and also the child cloning function, which leads to cloning of the complete object. When the parent objects are cloned with their containing objects it’s called as deep cloning and when only the parent is clones its termed as shallow cloning.
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 ABFPS (Abraham Became First President of States).
Structural Patterns
• Adapter:-Match interfaces of different classes.
• Bridge:-Separates an object’s abstraction from its implementation.
• Composite:-A tree structure of simple and composite objects.
• Decorator:-Add responsibilities to objects dynamically.
• Façade:-A single class that represents an entire subsystem.
• Flyweight:-A fine-grained instance used for efficient sharing.
• Proxy:-An object representing another object.
Note : To remember structural pattern best is (ABCDFFP)
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.
Note: – Just remember Music……. 2 MICS On TV (MMIICCSSOTV).
Finding duplicate rows in SQL
Normally we want to fetch this information that which row have duplicate value.So here i am sharing very easy solution for this.by using this query you can get which row have multiple entries.
SELECT surname, COUNT(surname) AS numOftimes FROM employee GROUP BY surname HAVING ( COUNT(surname) > 1 )
You could also use this technique to find rows that occur exactly once or n time:
SELECT surname FROM employee GROUP BY surname HAVING ( COUNT(surname) = 1 )
or for 'n' timesSELECT surname FROM employee GROUP BY surname HAVING ( COUNT(surname) = n )