<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Karthi2</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Karthi2"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Karthi2"/>
	<updated>2026-09-11T17:08:15Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71235</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71235"/>
		<updated>2012-11-24T17:27:17Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;ref&amp;gt;http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type&amp;lt;ref&amp;gt;http://www.fatagnus.com/program-to-an-interface-not-an-implementation/&amp;lt;/ref&amp;gt; &amp;lt;ref&amp;gt;http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;/ref&amp;gt;. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&amp;lt;ref&amp;gt;http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
An example why we have to program to an interface is shown below:&lt;br /&gt;
&amp;lt;pre&amp;gt;   &lt;br /&gt;
public ProcessedBeans processBeans(Beans beans){&lt;br /&gt;
    ProcessedBeans processedBeans = beans.getProcessedBeans();  &lt;br /&gt;
    return processedBeans;  &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above code, we are programming for an implementation assuming that beans is the only item that needs processing. But, as we know, this is not the case. We have to process other food items as well before consumption. Due to the way we have programmed it now we will have to add many more functions for each type of food item that needs processing. This can be avoided, however, by programming to an interface.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public ProcessedFood processFood(FoodItem foodItem){  &lt;br /&gt;
    ProcessedFood processedFood = foodItem.getProcessedItem();  &lt;br /&gt;
    return processedFood;&lt;br /&gt;
}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By doing so, we have eliminated the need to add new functions for each food type as already noted. The UML diagram for the interface would look something like this:-&lt;br /&gt;
&lt;br /&gt;
[[File:UML-Program_to_an_Interface.png]]&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&amp;lt;ref&amp;gt;http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;/ref&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
Inheritance is good to represent ''is-a'' relationships but is not suitable for portraying ''has-a'' relationships. Many relationships between classes or components do not fall into the ''is-a'' category. (for example, a Car class is likely not a HashMap, but it may have a HashMap). In these scenarios it follows the composition is a better idea for modeling relationships between classes rather than inheritance.&lt;br /&gt;
&lt;br /&gt;
Below is one simple example where composition is much suited than inheritance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Flight extends Journey {...}&lt;br /&gt;
Class Bus extends Journey {...}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, instead of having a sub-class for Flight, class Journey can have a new field which is TransportMode which represents different modes of transport such as flight, bus, train etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class TransportMode {&lt;br /&gt;
  TransportType type;&lt;br /&gt;
  double getCost(double distance) {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  TransportMode mode;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  double getCost() { mode.getCost( getDistance() ) }&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However this is not to say that inheritance should not be used at all. Below is another example which shows that inheritance is the one which we should be using. Here the Human class represents a ''is-a'' relationship with Animal class which is quite natural and the proper way to look at the classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Animal {&lt;br /&gt;
    private String name;&lt;br /&gt;
    public String getName(){&lt;br /&gt;
        return name;&lt;br /&gt;
    }&lt;br /&gt;
    abstract String isIntelligent();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Cat extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;No&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Human extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;Yes&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In short, one should use inheritance for behavioral purposes ie., subclasses should override methods to specialize the behavior of the method and the object itself.&lt;br /&gt;
&lt;br /&gt;
'''Benefits of object composition'''&amp;lt;ref&amp;gt;http://www.kuro5hin.org/story/2002/7/14/81923/3656&amp;lt;/ref&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* To favour composition over inheritance is a design principle that gives the design higher flexibility.&lt;br /&gt;
* Initial design becomes simple by avoiding hierarchical relationship among classes via inheritance and by identifying object behaviors in separate interfaces. &lt;br /&gt;
* Can easily accommodate future requirements without having to restructure large portions of code.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;/ref&amp;gt; &amp;lt;ref&amp;gt;http://www.kuro5hin.org/story/2002/7/14/81923/3656&amp;lt;/ref&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* All of the methods provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods.&lt;br /&gt;
* In inheritance the derived class only need to implement methods whose behavior needs to be modified.. &lt;br /&gt;
* Significantly less programming effort if only a handful of functions in the superclass needs to be overridden in the subclass.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
The key to identifying what should be variable lies in anticipating new requirements and changes to the existing requirements. The system must be designed in such a way so that it can evolve accordingly. Designing a robust system is we must take into account unforeseen changes to avoid a major design overhaul in future. Those changes might involve class redefinition and re-implementation, client modification, and retesting.Redesign affects many parts of the software system, and unanticipated changes are invariably expensive.&lt;br /&gt;
&lt;br /&gt;
Design patterns help you avoid this by ensuring that a system can change in specific ways. Each design pattern lets some aspect of system structure vary independently of other aspects, thereby making a system more robust to a particular kind of change.&lt;br /&gt;
&lt;br /&gt;
Below are some common causes of redesign along with the design pattern(s) that address them:&amp;lt;ref&amp;gt;http://www.palserv.com/dp/DesignPatternsOverview.html&amp;lt;/ref&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Creating an object by specifying a class explicitly:''' Specifying a class name when you create an object commits you to a particular implementation instead of a particular interface. This commitment can complicate future changes. To avoid it, create objects indirectly.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Factory_method_pattern Factory Method], [http://en.wikipedia.org/wiki/Prototype_pattern Prototype].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on specific operations:''' When you specify a particular operation, you commit to one way of satisfying a request. By avoiding hard-coded requests, you make it easier to change the way a request gets satisfied both at compile-time and at run-time.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on hardware and software platform:''' External operating system interfaces and application programming interfaces (APIs) are different on different hardware and software platforms. Software that depends on a particular platform will be harder to port to other platforms. It may even be difficult to keep it up to date on its native platform. It's important therefore to design your system to limit its platform dependencies.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on object representations or implementation:''' Clients that know how an object is represented, stored, located, or implemented might need to be changed when the object changes. Hiding this information from clients keeps changes from cascading.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Memento_pattern Memento], [http://en.wikipedia.org/wiki/Proxy_pattern Proxy].&lt;br /&gt;
&lt;br /&gt;
*'''Algorithmic dependencies:''' Algorithms are often extended, optimized, and replaced during development and reuse. Objects that depend on an algorithm will have to change when the algorithm changes. Therefore algorithms that are likely to change should be isolated.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Builder_pattern Builder], [http://en.wikipedia.org/wiki/Iterator_pattern Iterator], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy], [http://en.wikipedia.org/wiki/Template_method_pattern Template Method], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
*'''Tight coupling:''' Classes that are tightly coupled are hard to reuse in isolation, since they depend on each other. Tight coupling leads to monolithic systems, where you can't change or remove a class without understanding and changing many other classes. The system becomes a dense mass that's hard to learn, port, and maintain.Loose coupling increases the probability that a class can be reused by itself and that a system can be learned, ported, modified, and extended more easily. Design patterns use techniques such as abstract coupling and layering to promote loosely coupled systems.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command], [http://en.wikipedia.org/wiki/Facade_pattern Facade], [http://en.wikipedia.org/wiki/Mediator_pattern Mediator], [http://en.wikipedia.org/wiki/Observer_pattern Observer].&lt;br /&gt;
&lt;br /&gt;
*'''Extending functionality by subclassing:''' Customizing an object by subclassing often isn't easy. Every new class has a fixed implementation overhead (initialization, finalization, etc.). Defining a subclass also requires an in-depth understanding of the parent class. For example, &lt;br /&gt;
&lt;br /&gt;
  Overriding one operation might require overriding another. An overridden operation might be required &lt;br /&gt;
  to call an inherited operation. And subclassing can lead to an explosion of classes, because you might have to introduce&lt;br /&gt;
  many new subclasses for even a simple extension.&lt;br /&gt;
&lt;br /&gt;
Object composition in general and delegation in particular provide flexible alternatives to inheritance for combining behavior.   New functionality can be added to an application by composing existing objects in new ways rather than by defining new subclasses of existing classes. On the other hand, heavy use of object composition can make designs harder to understand. Many design patterns&lt;br /&gt;
produce designs in which you can introduce customized functionality just by defining one subclass and composing its instances with existing ones.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Composite_pattern Composite], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Observer_pattern Observer], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy].&lt;br /&gt;
&lt;br /&gt;
*'''Inability to alter classes conveniently:''' Sometimes you have to modify a class that can't be modified conveniently. Perhaps you need the source code and don't have it (as may be the case with a commercial class library). Or maybe any change would require modifying lots of existing subclasses. Design patterns offer ways to modify classes in such circumstances.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Adapter_pattern Adapter], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
These examples reflect the flexibility that design patterns can help you build into your software. How crucial such flexibility is depends on the kind of software you're building.&lt;br /&gt;
&lt;br /&gt;
'''Advantages:'''&lt;br /&gt;
*Enables large scale reuse of software.&lt;br /&gt;
*Helps in improving developer communication.&lt;br /&gt;
*Captures expert knowledge and design trade-offs and make expertise widely available&lt;br /&gt;
&lt;br /&gt;
'''Disadvantages:'''&lt;br /&gt;
*Does not lead to direct code reuse and is complex in nature.&lt;br /&gt;
*They are validated by experience and discussion.&lt;br /&gt;
*They consume more memory because of generalized format.&lt;br /&gt;
*They are optimized to store any kind of data. This can degrade performance.&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
2. http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
4. http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71234</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71234"/>
		<updated>2012-11-24T17:26:58Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Consider what should be variable in your design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;ref&amp;gt;http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type&amp;lt;ref&amp;gt;http://www.fatagnus.com/program-to-an-interface-not-an-implementation/&amp;lt;/ref&amp;gt; &amp;lt;ref&amp;gt;http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;/ref&amp;gt;. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&amp;lt;ref&amp;gt;http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
An example why we have to program to an interface is shown below:&lt;br /&gt;
&amp;lt;pre&amp;gt;   &lt;br /&gt;
public ProcessedBeans processBeans(Beans beans){&lt;br /&gt;
    ProcessedBeans processedBeans = beans.getProcessedBeans();  &lt;br /&gt;
    return processedBeans;  &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above code, we are programming for an implementation assuming that beans is the only item that needs processing. But, as we know, this is not the case. We have to process other food items as well before consumption. Due to the way we have programmed it now we will have to add many more functions for each type of food item that needs processing. This can be avoided, however, by programming to an interface.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public ProcessedFood processFood(FoodItem foodItem){  &lt;br /&gt;
    ProcessedFood processedFood = foodItem.getProcessedItem();  &lt;br /&gt;
    return processedFood;&lt;br /&gt;
}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By doing so, we have eliminated the need to add new functions for each food type as already noted. The UML diagram for the interface would look something like this:-&lt;br /&gt;
&lt;br /&gt;
[[File:UML-Program_to_an_Interface.png]]&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&amp;lt;ref&amp;gt;http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;/ref&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
Inheritance is good to represent ''is-a'' relationships but is not suitable for portraying ''has-a'' relationships. Many relationships between classes or components do not fall into the ''is-a'' category. (for example, a Car class is likely not a HashMap, but it may have a HashMap). In these scenarios it follows the composition is a better idea for modeling relationships between classes rather than inheritance.&lt;br /&gt;
&lt;br /&gt;
Below is one simple example where composition is much suited than inheritance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Flight extends Journey {...}&lt;br /&gt;
Class Bus extends Journey {...}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, instead of having a sub-class for Flight, class Journey can have a new field which is TransportMode which represents different modes of transport such as flight, bus, train etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class TransportMode {&lt;br /&gt;
  TransportType type;&lt;br /&gt;
  double getCost(double distance) {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  TransportMode mode;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  double getCost() { mode.getCost( getDistance() ) }&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However this is not to say that inheritance should not be used at all. Below is another example which shows that inheritance is the one which we should be using. Here the Human class represents a ''is-a'' relationship with Animal class which is quite natural and the proper way to look at the classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Animal {&lt;br /&gt;
    private String name;&lt;br /&gt;
    public String getName(){&lt;br /&gt;
        return name;&lt;br /&gt;
    }&lt;br /&gt;
    abstract String isIntelligent();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Cat extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;No&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Human extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;Yes&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In short, one should use inheritance for behavioral purposes ie., subclasses should override methods to specialize the behavior of the method and the object itself.&lt;br /&gt;
&lt;br /&gt;
'''Benefits of object composition'''&amp;lt;ref&amp;gt;http://www.kuro5hin.org/story/2002/7/14/81923/3656&amp;lt;/ref&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* To favour composition over inheritance is a design principle that gives the design higher flexibility.&lt;br /&gt;
* Initial design becomes simple by avoiding hierarchical relationship among classes via inheritance and by identifying object behaviors in separate interfaces. &lt;br /&gt;
* Can easily accommodate future requirements without having to restructure large portions of code.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;/ref&amp;gt; &amp;lt;ref&amp;gt;http://www.kuro5hin.org/story/2002/7/14/81923/3656&amp;lt;/ref&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* All of the methods provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods.&lt;br /&gt;
* In inheritance the derived class only need to implement methods whose behavior needs to be modified.. &lt;br /&gt;
* Significantly less programming effort if only a handful of functions in the superclass needs to be overridden in the subclass.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
The key to identifying what should be variable lies in anticipating new requirements and changes to the existing requirements. The system must be designed in such a way so that it can evolve accordingly. Designing a robust system is we must take into account unforeseen changes to avoid a major design overhaul in future. Those changes might involve class redefinition and re-implementation, client modification, and retesting.Redesign affects many parts of the software system, and unanticipated changes are invariably expensive.&lt;br /&gt;
&lt;br /&gt;
Design patterns help you avoid this by ensuring that a system can change in specific ways. Each design pattern lets some aspect of system structure vary independently of other aspects, thereby making a system more robust to a particular kind of change.&lt;br /&gt;
&lt;br /&gt;
Below are some common causes of redesign along with the design pattern(s) that address them:&amp;lt;ref&amp;gt;http://www.palserv.com/dp/DesignPatternsOverview.html&amp;lt;/ref&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Creating an object by specifying a class explicitly:''' Specifying a class name when you create an object commits you to a particular implementation instead of a particular interface. This commitment can complicate future changes. To avoid it, create objects indirectly.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Factory_method_pattern Factory Method], [http://en.wikipedia.org/wiki/Prototype_pattern Prototype].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on specific operations:''' When you specify a particular operation, you commit to one way of satisfying a request. By avoiding hard-coded requests, you make it easier to change the way a request gets satisfied both at compile-time and at run-time.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on hardware and software platform:''' External operating system interfaces and application programming interfaces (APIs) are different on different hardware and software platforms. Software that depends on a particular platform will be harder to port to other platforms. It may even be difficult to keep it up to date on its native platform. It's important therefore to design your system to limit its platform dependencies.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on object representations or implementation:''' Clients that know how an object is represented, stored, located, or implemented might need to be changed when the object changes. Hiding this information from clients keeps changes from cascading.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Memento_pattern Memento], [http://en.wikipedia.org/wiki/Proxy_pattern Proxy].&lt;br /&gt;
&lt;br /&gt;
*'''Algorithmic dependencies:''' Algorithms are often extended, optimized, and replaced during development and reuse. Objects that depend on an algorithm will have to change when the algorithm changes. Therefore algorithms that are likely to change should be isolated.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Builder_pattern Builder], [http://en.wikipedia.org/wiki/Iterator_pattern Iterator], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy], [http://en.wikipedia.org/wiki/Template_method_pattern Template Method], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
*'''Tight coupling:''' Classes that are tightly coupled are hard to reuse in isolation, since they depend on each other. Tight coupling leads to monolithic systems, where you can't change or remove a class without understanding and changing many other classes. The system becomes a dense mass that's hard to learn, port, and maintain.Loose coupling increases the probability that a class can be reused by itself and that a system can be learned, ported, modified, and extended more easily. Design patterns use techniques such as abstract coupling and layering to promote loosely coupled systems.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command], [http://en.wikipedia.org/wiki/Facade_pattern Facade], [http://en.wikipedia.org/wiki/Mediator_pattern Mediator], [http://en.wikipedia.org/wiki/Observer_pattern Observer].&lt;br /&gt;
&lt;br /&gt;
*'''Extending functionality by subclassing:''' Customizing an object by subclassing often isn't easy. Every new class has a fixed implementation overhead (initialization, finalization, etc.). Defining a subclass also requires an in-depth understanding of the parent class. For example, &lt;br /&gt;
&lt;br /&gt;
  Overriding one operation might require overriding another. An overridden operation might be required &lt;br /&gt;
  to call an inherited operation. And subclassing can lead to an explosion of classes, because you might have to introduce&lt;br /&gt;
  many new subclasses for even a simple extension.&lt;br /&gt;
&lt;br /&gt;
Object composition in general and delegation in particular provide flexible alternatives to inheritance for combining behavior.   New functionality can be added to an application by composing existing objects in new ways rather than by defining new subclasses of existing classes. On the other hand, heavy use of object composition can make designs harder to understand. Many design patterns&lt;br /&gt;
produce designs in which you can introduce customized functionality just by defining one subclass and composing its instances with existing ones.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Composite_pattern Composite], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Observer_pattern Observer], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy].&lt;br /&gt;
&lt;br /&gt;
*'''Inability to alter classes conveniently:''' Sometimes you have to modify a class that can't be modified conveniently. Perhaps you need the source code and don't have it (as may be the case with a commercial class library). Or maybe any change would require modifying lots of existing subclasses. Design patterns offer ways to modify classes in such circumstances.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Adapter_pattern Adapter], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
These examples reflect the flexibility that design patterns can help you build into your software. How crucial such flexibility is depends on the kind of software you're building.&lt;br /&gt;
&lt;br /&gt;
'''Advantages:'''&lt;br /&gt;
*Enables large scale reuse of software.&lt;br /&gt;
*Helps in improving developer communication.&lt;br /&gt;
*Captures expert knowledge and design trade-offs and make expertise widely available&lt;br /&gt;
&lt;br /&gt;
'''Disadvantages:'''&lt;br /&gt;
*Does not lead to direct code reuse and is complex in nature.&lt;br /&gt;
*They are validated by experience and discussion.&lt;br /&gt;
*They consume more memory because of generalized format.&lt;br /&gt;
*They are optimized to store any kind of data. This can degrade performance.&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
2. http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
4. http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;br /&gt;
http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance/&amp;lt;br&amp;gt;&lt;br /&gt;
http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.kuro5hin.org/story/2002/7/14/81923/3656&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.palserv.com/dp/DesignPatternsOverview.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71233</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71233"/>
		<updated>2012-11-24T17:25:42Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Favor object composition over class inheritance */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;ref&amp;gt;http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type&amp;lt;ref&amp;gt;http://www.fatagnus.com/program-to-an-interface-not-an-implementation/&amp;lt;/ref&amp;gt; &amp;lt;ref&amp;gt;http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;/ref&amp;gt;. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&amp;lt;ref&amp;gt;http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
An example why we have to program to an interface is shown below:&lt;br /&gt;
&amp;lt;pre&amp;gt;   &lt;br /&gt;
public ProcessedBeans processBeans(Beans beans){&lt;br /&gt;
    ProcessedBeans processedBeans = beans.getProcessedBeans();  &lt;br /&gt;
    return processedBeans;  &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above code, we are programming for an implementation assuming that beans is the only item that needs processing. But, as we know, this is not the case. We have to process other food items as well before consumption. Due to the way we have programmed it now we will have to add many more functions for each type of food item that needs processing. This can be avoided, however, by programming to an interface.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public ProcessedFood processFood(FoodItem foodItem){  &lt;br /&gt;
    ProcessedFood processedFood = foodItem.getProcessedItem();  &lt;br /&gt;
    return processedFood;&lt;br /&gt;
}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By doing so, we have eliminated the need to add new functions for each food type as already noted. The UML diagram for the interface would look something like this:-&lt;br /&gt;
&lt;br /&gt;
[[File:UML-Program_to_an_Interface.png]]&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&amp;lt;ref&amp;gt;http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;/ref&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
Inheritance is good to represent ''is-a'' relationships but is not suitable for portraying ''has-a'' relationships. Many relationships between classes or components do not fall into the ''is-a'' category. (for example, a Car class is likely not a HashMap, but it may have a HashMap). In these scenarios it follows the composition is a better idea for modeling relationships between classes rather than inheritance.&lt;br /&gt;
&lt;br /&gt;
Below is one simple example where composition is much suited than inheritance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Flight extends Journey {...}&lt;br /&gt;
Class Bus extends Journey {...}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, instead of having a sub-class for Flight, class Journey can have a new field which is TransportMode which represents different modes of transport such as flight, bus, train etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class TransportMode {&lt;br /&gt;
  TransportType type;&lt;br /&gt;
  double getCost(double distance) {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  TransportMode mode;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  double getCost() { mode.getCost( getDistance() ) }&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However this is not to say that inheritance should not be used at all. Below is another example which shows that inheritance is the one which we should be using. Here the Human class represents a ''is-a'' relationship with Animal class which is quite natural and the proper way to look at the classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Animal {&lt;br /&gt;
    private String name;&lt;br /&gt;
    public String getName(){&lt;br /&gt;
        return name;&lt;br /&gt;
    }&lt;br /&gt;
    abstract String isIntelligent();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Cat extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;No&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Human extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;Yes&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In short, one should use inheritance for behavioral purposes ie., subclasses should override methods to specialize the behavior of the method and the object itself.&lt;br /&gt;
&lt;br /&gt;
'''Benefits of object composition'''&amp;lt;ref&amp;gt;http://www.kuro5hin.org/story/2002/7/14/81923/3656&amp;lt;/ref&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* To favour composition over inheritance is a design principle that gives the design higher flexibility.&lt;br /&gt;
* Initial design becomes simple by avoiding hierarchical relationship among classes via inheritance and by identifying object behaviors in separate interfaces. &lt;br /&gt;
* Can easily accommodate future requirements without having to restructure large portions of code.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;/ref&amp;gt; &amp;lt;ref&amp;gt;http://www.kuro5hin.org/story/2002/7/14/81923/3656&amp;lt;/ref&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* All of the methods provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods.&lt;br /&gt;
* In inheritance the derived class only need to implement methods whose behavior needs to be modified.. &lt;br /&gt;
* Significantly less programming effort if only a handful of functions in the superclass needs to be overridden in the subclass.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
The key to identifying what should be variable lies in anticipating new requirements and changes to the existing requirements. The system must be designed in such a way so that it can evolve accordingly. Designing a robust system is we must take into account unforeseen changes to avoid a major design overhaul in future. Those changes might involve class redefinition and re-implementation, client modification, and retesting.Redesign affects many parts of the software system, and unanticipated changes are invariably expensive.&lt;br /&gt;
&lt;br /&gt;
Design patterns help you avoid this by ensuring that a system can change in specific ways. Each design pattern lets some aspect of system structure vary independently of other aspects, thereby making a system more robust to a particular kind of change.&lt;br /&gt;
&lt;br /&gt;
Below are some common causes of redesign along with the design pattern(s) that address them:&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Creating an object by specifying a class explicitly:''' Specifying a class name when you create an object commits you to a particular implementation instead of a particular interface. This commitment can complicate future changes. To avoid it, create objects indirectly.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Factory_method_pattern Factory Method], [http://en.wikipedia.org/wiki/Prototype_pattern Prototype].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on specific operations:''' When you specify a particular operation, you commit to one way of satisfying a request. By avoiding hard-coded requests, you make it easier to change the way a request gets satisfied both at compile-time and at run-time.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on hardware and software platform:''' External operating system interfaces and application programming interfaces (APIs) are different on different hardware and software platforms. Software that depends on a particular platform will be harder to port to other platforms. It may even be difficult to keep it up to date on its native platform. It's important therefore to design your system to limit its platform dependencies.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on object representations or implementation:''' Clients that know how an object is represented, stored, located, or implemented might need to be changed when the object changes. Hiding this information from clients keeps changes from cascading.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Memento_pattern Memento], [http://en.wikipedia.org/wiki/Proxy_pattern Proxy].&lt;br /&gt;
&lt;br /&gt;
*'''Algorithmic dependencies:''' Algorithms are often extended, optimized, and replaced during development and reuse. Objects that depend on an algorithm will have to change when the algorithm changes. Therefore algorithms that are likely to change should be isolated.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Builder_pattern Builder], [http://en.wikipedia.org/wiki/Iterator_pattern Iterator], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy], [http://en.wikipedia.org/wiki/Template_method_pattern Template Method], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
*'''Tight coupling:''' Classes that are tightly coupled are hard to reuse in isolation, since they depend on each other. Tight coupling leads to monolithic systems, where you can't change or remove a class without understanding and changing many other classes. The system becomes a dense mass that's hard to learn, port, and maintain.Loose coupling increases the probability that a class can be reused by itself and that a system can be learned, ported, modified, and extended more easily. Design patterns use techniques such as abstract coupling and layering to promote loosely coupled systems.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command], [http://en.wikipedia.org/wiki/Facade_pattern Facade], [http://en.wikipedia.org/wiki/Mediator_pattern Mediator], [http://en.wikipedia.org/wiki/Observer_pattern Observer].&lt;br /&gt;
&lt;br /&gt;
*'''Extending functionality by subclassing:''' Customizing an object by subclassing often isn't easy. Every new class has a fixed implementation overhead (initialization, finalization, etc.). Defining a subclass also requires an in-depth understanding of the parent class. For example, &lt;br /&gt;
&lt;br /&gt;
  Overriding one operation might require overriding another. An overridden operation might be required &lt;br /&gt;
  to call an inherited operation. And subclassing can lead to an explosion of classes, because you might have to introduce&lt;br /&gt;
  many new subclasses for even a simple extension.&lt;br /&gt;
&lt;br /&gt;
Object composition in general and delegation in particular provide flexible alternatives to inheritance for combining behavior.   New functionality can be added to an application by composing existing objects in new ways rather than by defining new subclasses of existing classes. On the other hand, heavy use of object composition can make designs harder to understand. Many design patterns&lt;br /&gt;
produce designs in which you can introduce customized functionality just by defining one subclass and composing its instances with existing ones.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Composite_pattern Composite], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Observer_pattern Observer], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy].&lt;br /&gt;
&lt;br /&gt;
*'''Inability to alter classes conveniently:''' Sometimes you have to modify a class that can't be modified conveniently. Perhaps you need the source code and don't have it (as may be the case with a commercial class library). Or maybe any change would require modifying lots of existing subclasses. Design patterns offer ways to modify classes in such circumstances.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Adapter_pattern Adapter], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
These examples reflect the flexibility that design patterns can help you build into your software. How crucial such flexibility is depends on the kind of software you're building.&lt;br /&gt;
&lt;br /&gt;
'''Advantages:'''&lt;br /&gt;
*Enables large scale reuse of software.&lt;br /&gt;
*Helps in improving developer communication.&lt;br /&gt;
*Captures expert knowledge and design trade-offs and make expertise widely available&lt;br /&gt;
&lt;br /&gt;
'''Disadvantages:'''&lt;br /&gt;
*Does not lead to direct code reuse and is complex in nature.&lt;br /&gt;
*They are validated by experience and discussion.&lt;br /&gt;
*They consume more memory because of generalized format.&lt;br /&gt;
*They are optimized to store any kind of data. This can degrade performance.&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
2. http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
4. http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;br /&gt;
http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance/&amp;lt;br&amp;gt;&lt;br /&gt;
http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.kuro5hin.org/story/2002/7/14/81923/3656&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.palserv.com/dp/DesignPatternsOverview.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71232</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71232"/>
		<updated>2012-11-24T17:19:33Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* See Also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;ref&amp;gt;http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type&amp;lt;ref&amp;gt;http://www.fatagnus.com/program-to-an-interface-not-an-implementation/&amp;lt;/ref&amp;gt; &amp;lt;ref&amp;gt;http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;/ref&amp;gt;. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&amp;lt;ref&amp;gt;http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
An example why we have to program to an interface is shown below:&lt;br /&gt;
&amp;lt;pre&amp;gt;   &lt;br /&gt;
public ProcessedBeans processBeans(Beans beans){&lt;br /&gt;
    ProcessedBeans processedBeans = beans.getProcessedBeans();  &lt;br /&gt;
    return processedBeans;  &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above code, we are programming for an implementation assuming that beans is the only item that needs processing. But, as we know, this is not the case. We have to process other food items as well before consumption. Due to the way we have programmed it now we will have to add many more functions for each type of food item that needs processing. This can be avoided, however, by programming to an interface.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public ProcessedFood processFood(FoodItem foodItem){  &lt;br /&gt;
    ProcessedFood processedFood = foodItem.getProcessedItem();  &lt;br /&gt;
    return processedFood;&lt;br /&gt;
}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By doing so, we have eliminated the need to add new functions for each food type as already noted. The UML diagram for the interface would look something like this:-&lt;br /&gt;
&lt;br /&gt;
[[File:UML-Program_to_an_Interface.png]]&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&amp;lt;ref&amp;gt;http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;/ref&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
Inheritance is good to represent ''is-a'' relationships but is not suitable for portraying ''has-a'' relationships. Many relationships between classes or components do not fall into the ''is-a'' category. (for example, a Car class is likely not a HashMap, but it may have a HashMap). In these scenarios it follows the composition is a better idea for modeling relationships between classes rather than inheritance.&lt;br /&gt;
&lt;br /&gt;
Below is one simple example where composition is much suited than inheritance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Flight extends Journey {...}&lt;br /&gt;
Class Bus extends Journey {...}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, instead of having a sub-class for Flight, class Journey can have a new field which is TransportMode which represents different modes of transport such as flight, bus, train etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class TransportMode {&lt;br /&gt;
  TransportType type;&lt;br /&gt;
  double getCost(double distance) {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  TransportMode mode;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  double getCost() { mode.getCost( getDistance() ) }&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However this is not to say that inheritance should not be used at all. Below is another example which shows that inheritance is the one which we should be using. Here the Human class represents a ''is-a'' relationship with Animal class which is quite natural and the proper way to look at the classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Animal {&lt;br /&gt;
    private String name;&lt;br /&gt;
    public String getName(){&lt;br /&gt;
        return name;&lt;br /&gt;
    }&lt;br /&gt;
    abstract String isIntelligent();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Cat extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;No&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Human extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;Yes&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In short, one should use inheritance for behavioral purposes ie., subclasses should override methods to specialize the behavior of the method and the object itself.&lt;br /&gt;
&lt;br /&gt;
'''Benefits of object composition'''&amp;lt;br&amp;gt;&lt;br /&gt;
* To favour composition over inheritance is a design principle that gives the design higher flexibility.&lt;br /&gt;
* Initial design becomes simple by avoiding hierarchical relationship among classes via inheritance and by identifying object behaviors in separate interfaces. &lt;br /&gt;
* Can easily accommodate future requirements without having to restructure large portions of code.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;/ref&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* All of the methods provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods.&lt;br /&gt;
* In inheritance the derived class only need to implement methods whose behavior needs to be modified.. &lt;br /&gt;
* Significantly less programming effort if only a handful of functions in the superclass needs to be overridden in the subclass.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
The key to identifying what should be variable lies in anticipating new requirements and changes to the existing requirements. The system must be designed in such a way so that it can evolve accordingly. Designing a robust system is we must take into account unforeseen changes to avoid a major design overhaul in future. Those changes might involve class redefinition and re-implementation, client modification, and retesting.Redesign affects many parts of the software system, and unanticipated changes are invariably expensive.&lt;br /&gt;
&lt;br /&gt;
Design patterns help you avoid this by ensuring that a system can change in specific ways. Each design pattern lets some aspect of system structure vary independently of other aspects, thereby making a system more robust to a particular kind of change.&lt;br /&gt;
&lt;br /&gt;
Below are some common causes of redesign along with the design pattern(s) that address them:&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Creating an object by specifying a class explicitly:''' Specifying a class name when you create an object commits you to a particular implementation instead of a particular interface. This commitment can complicate future changes. To avoid it, create objects indirectly.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Factory_method_pattern Factory Method], [http://en.wikipedia.org/wiki/Prototype_pattern Prototype].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on specific operations:''' When you specify a particular operation, you commit to one way of satisfying a request. By avoiding hard-coded requests, you make it easier to change the way a request gets satisfied both at compile-time and at run-time.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on hardware and software platform:''' External operating system interfaces and application programming interfaces (APIs) are different on different hardware and software platforms. Software that depends on a particular platform will be harder to port to other platforms. It may even be difficult to keep it up to date on its native platform. It's important therefore to design your system to limit its platform dependencies.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on object representations or implementation:''' Clients that know how an object is represented, stored, located, or implemented might need to be changed when the object changes. Hiding this information from clients keeps changes from cascading.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Memento_pattern Memento], [http://en.wikipedia.org/wiki/Proxy_pattern Proxy].&lt;br /&gt;
&lt;br /&gt;
*'''Algorithmic dependencies:''' Algorithms are often extended, optimized, and replaced during development and reuse. Objects that depend on an algorithm will have to change when the algorithm changes. Therefore algorithms that are likely to change should be isolated.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Builder_pattern Builder], [http://en.wikipedia.org/wiki/Iterator_pattern Iterator], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy], [http://en.wikipedia.org/wiki/Template_method_pattern Template Method], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
*'''Tight coupling:''' Classes that are tightly coupled are hard to reuse in isolation, since they depend on each other. Tight coupling leads to monolithic systems, where you can't change or remove a class without understanding and changing many other classes. The system becomes a dense mass that's hard to learn, port, and maintain.Loose coupling increases the probability that a class can be reused by itself and that a system can be learned, ported, modified, and extended more easily. Design patterns use techniques such as abstract coupling and layering to promote loosely coupled systems.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command], [http://en.wikipedia.org/wiki/Facade_pattern Facade], [http://en.wikipedia.org/wiki/Mediator_pattern Mediator], [http://en.wikipedia.org/wiki/Observer_pattern Observer].&lt;br /&gt;
&lt;br /&gt;
*'''Extending functionality by subclassing:''' Customizing an object by subclassing often isn't easy. Every new class has a fixed implementation overhead (initialization, finalization, etc.). Defining a subclass also requires an in-depth understanding of the parent class. For example, &lt;br /&gt;
&lt;br /&gt;
  Overriding one operation might require overriding another. An overridden operation might be required &lt;br /&gt;
  to call an inherited operation. And subclassing can lead to an explosion of classes, because you might have to introduce&lt;br /&gt;
  many new subclasses for even a simple extension.&lt;br /&gt;
&lt;br /&gt;
Object composition in general and delegation in particular provide flexible alternatives to inheritance for combining behavior.   New functionality can be added to an application by composing existing objects in new ways rather than by defining new subclasses of existing classes. On the other hand, heavy use of object composition can make designs harder to understand. Many design patterns&lt;br /&gt;
produce designs in which you can introduce customized functionality just by defining one subclass and composing its instances with existing ones.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Composite_pattern Composite], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Observer_pattern Observer], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy].&lt;br /&gt;
&lt;br /&gt;
*'''Inability to alter classes conveniently:''' Sometimes you have to modify a class that can't be modified conveniently. Perhaps you need the source code and don't have it (as may be the case with a commercial class library). Or maybe any change would require modifying lots of existing subclasses. Design patterns offer ways to modify classes in such circumstances.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Adapter_pattern Adapter], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
These examples reflect the flexibility that design patterns can help you build into your software. How crucial such flexibility is depends on the kind of software you're building.&lt;br /&gt;
&lt;br /&gt;
'''Advantages:'''&lt;br /&gt;
*Enables large scale reuse of software.&lt;br /&gt;
*Helps in improving developer communication.&lt;br /&gt;
*Captures expert knowledge and design trade-offs and make expertise widely available&lt;br /&gt;
&lt;br /&gt;
'''Disadvantages:'''&lt;br /&gt;
*Does not lead to direct code reuse and is complex in nature.&lt;br /&gt;
*They are validated by experience and discussion.&lt;br /&gt;
*They consume more memory because of generalized format.&lt;br /&gt;
*They are optimized to store any kind of data. This can degrade performance.&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
2. http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
4. http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;br /&gt;
http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance/&amp;lt;br&amp;gt;&lt;br /&gt;
http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.kuro5hin.org/story/2002/7/14/81923/3656&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.palserv.com/dp/DesignPatternsOverview.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71231</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71231"/>
		<updated>2012-11-24T17:17:03Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Favor object composition over class inheritance */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;ref&amp;gt;http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type&amp;lt;ref&amp;gt;http://www.fatagnus.com/program-to-an-interface-not-an-implementation/&amp;lt;/ref&amp;gt; &amp;lt;ref&amp;gt;http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;/ref&amp;gt;. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&amp;lt;ref&amp;gt;http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
An example why we have to program to an interface is shown below:&lt;br /&gt;
&amp;lt;pre&amp;gt;   &lt;br /&gt;
public ProcessedBeans processBeans(Beans beans){&lt;br /&gt;
    ProcessedBeans processedBeans = beans.getProcessedBeans();  &lt;br /&gt;
    return processedBeans;  &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above code, we are programming for an implementation assuming that beans is the only item that needs processing. But, as we know, this is not the case. We have to process other food items as well before consumption. Due to the way we have programmed it now we will have to add many more functions for each type of food item that needs processing. This can be avoided, however, by programming to an interface.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public ProcessedFood processFood(FoodItem foodItem){  &lt;br /&gt;
    ProcessedFood processedFood = foodItem.getProcessedItem();  &lt;br /&gt;
    return processedFood;&lt;br /&gt;
}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By doing so, we have eliminated the need to add new functions for each food type as already noted. The UML diagram for the interface would look something like this:-&lt;br /&gt;
&lt;br /&gt;
[[File:UML-Program_to_an_Interface.png]]&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&amp;lt;ref&amp;gt;http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;/ref&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
Inheritance is good to represent ''is-a'' relationships but is not suitable for portraying ''has-a'' relationships. Many relationships between classes or components do not fall into the ''is-a'' category. (for example, a Car class is likely not a HashMap, but it may have a HashMap). In these scenarios it follows the composition is a better idea for modeling relationships between classes rather than inheritance.&lt;br /&gt;
&lt;br /&gt;
Below is one simple example where composition is much suited than inheritance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Flight extends Journey {...}&lt;br /&gt;
Class Bus extends Journey {...}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, instead of having a sub-class for Flight, class Journey can have a new field which is TransportMode which represents different modes of transport such as flight, bus, train etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class TransportMode {&lt;br /&gt;
  TransportType type;&lt;br /&gt;
  double getCost(double distance) {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  TransportMode mode;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  double getCost() { mode.getCost( getDistance() ) }&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However this is not to say that inheritance should not be used at all. Below is another example which shows that inheritance is the one which we should be using. Here the Human class represents a ''is-a'' relationship with Animal class which is quite natural and the proper way to look at the classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Animal {&lt;br /&gt;
    private String name;&lt;br /&gt;
    public String getName(){&lt;br /&gt;
        return name;&lt;br /&gt;
    }&lt;br /&gt;
    abstract String isIntelligent();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Cat extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;No&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Human extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;Yes&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In short, one should use inheritance for behavioral purposes ie., subclasses should override methods to specialize the behavior of the method and the object itself.&lt;br /&gt;
&lt;br /&gt;
'''Benefits of object composition'''&amp;lt;br&amp;gt;&lt;br /&gt;
* To favour composition over inheritance is a design principle that gives the design higher flexibility.&lt;br /&gt;
* Initial design becomes simple by avoiding hierarchical relationship among classes via inheritance and by identifying object behaviors in separate interfaces. &lt;br /&gt;
* Can easily accommodate future requirements without having to restructure large portions of code.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;/ref&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* All of the methods provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods.&lt;br /&gt;
* In inheritance the derived class only need to implement methods whose behavior needs to be modified.. &lt;br /&gt;
* Significantly less programming effort if only a handful of functions in the superclass needs to be overridden in the subclass.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
The key to identifying what should be variable lies in anticipating new requirements and changes to the existing requirements. The system must be designed in such a way so that it can evolve accordingly. Designing a robust system is we must take into account unforeseen changes to avoid a major design overhaul in future. Those changes might involve class redefinition and re-implementation, client modification, and retesting.Redesign affects many parts of the software system, and unanticipated changes are invariably expensive.&lt;br /&gt;
&lt;br /&gt;
Design patterns help you avoid this by ensuring that a system can change in specific ways. Each design pattern lets some aspect of system structure vary independently of other aspects, thereby making a system more robust to a particular kind of change.&lt;br /&gt;
&lt;br /&gt;
Below are some common causes of redesign along with the design pattern(s) that address them:&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Creating an object by specifying a class explicitly:''' Specifying a class name when you create an object commits you to a particular implementation instead of a particular interface. This commitment can complicate future changes. To avoid it, create objects indirectly.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Factory_method_pattern Factory Method], [http://en.wikipedia.org/wiki/Prototype_pattern Prototype].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on specific operations:''' When you specify a particular operation, you commit to one way of satisfying a request. By avoiding hard-coded requests, you make it easier to change the way a request gets satisfied both at compile-time and at run-time.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on hardware and software platform:''' External operating system interfaces and application programming interfaces (APIs) are different on different hardware and software platforms. Software that depends on a particular platform will be harder to port to other platforms. It may even be difficult to keep it up to date on its native platform. It's important therefore to design your system to limit its platform dependencies.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on object representations or implementation:''' Clients that know how an object is represented, stored, located, or implemented might need to be changed when the object changes. Hiding this information from clients keeps changes from cascading.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Memento_pattern Memento], [http://en.wikipedia.org/wiki/Proxy_pattern Proxy].&lt;br /&gt;
&lt;br /&gt;
*'''Algorithmic dependencies:''' Algorithms are often extended, optimized, and replaced during development and reuse. Objects that depend on an algorithm will have to change when the algorithm changes. Therefore algorithms that are likely to change should be isolated.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Builder_pattern Builder], [http://en.wikipedia.org/wiki/Iterator_pattern Iterator], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy], [http://en.wikipedia.org/wiki/Template_method_pattern Template Method], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
*'''Tight coupling:''' Classes that are tightly coupled are hard to reuse in isolation, since they depend on each other. Tight coupling leads to monolithic systems, where you can't change or remove a class without understanding and changing many other classes. The system becomes a dense mass that's hard to learn, port, and maintain.Loose coupling increases the probability that a class can be reused by itself and that a system can be learned, ported, modified, and extended more easily. Design patterns use techniques such as abstract coupling and layering to promote loosely coupled systems.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command], [http://en.wikipedia.org/wiki/Facade_pattern Facade], [http://en.wikipedia.org/wiki/Mediator_pattern Mediator], [http://en.wikipedia.org/wiki/Observer_pattern Observer].&lt;br /&gt;
&lt;br /&gt;
*'''Extending functionality by subclassing:''' Customizing an object by subclassing often isn't easy. Every new class has a fixed implementation overhead (initialization, finalization, etc.). Defining a subclass also requires an in-depth understanding of the parent class. For example, &lt;br /&gt;
&lt;br /&gt;
  Overriding one operation might require overriding another. An overridden operation might be required &lt;br /&gt;
  to call an inherited operation. And subclassing can lead to an explosion of classes, because you might have to introduce&lt;br /&gt;
  many new subclasses for even a simple extension.&lt;br /&gt;
&lt;br /&gt;
Object composition in general and delegation in particular provide flexible alternatives to inheritance for combining behavior.   New functionality can be added to an application by composing existing objects in new ways rather than by defining new subclasses of existing classes. On the other hand, heavy use of object composition can make designs harder to understand. Many design patterns&lt;br /&gt;
produce designs in which you can introduce customized functionality just by defining one subclass and composing its instances with existing ones.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Composite_pattern Composite], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Observer_pattern Observer], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy].&lt;br /&gt;
&lt;br /&gt;
*'''Inability to alter classes conveniently:''' Sometimes you have to modify a class that can't be modified conveniently. Perhaps you need the source code and don't have it (as may be the case with a commercial class library). Or maybe any change would require modifying lots of existing subclasses. Design patterns offer ways to modify classes in such circumstances.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Adapter_pattern Adapter], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
These examples reflect the flexibility that design patterns can help you build into your software. How crucial such flexibility is depends on the kind of software you're building.&lt;br /&gt;
&lt;br /&gt;
'''Advantages:'''&lt;br /&gt;
*Enables large scale reuse of software.&lt;br /&gt;
*Helps in improving developer communication.&lt;br /&gt;
*Captures expert knowledge and design trade-offs and make expertise widely available&lt;br /&gt;
&lt;br /&gt;
'''Disadvantages:'''&lt;br /&gt;
*Does not lead to direct code reuse and is complex in nature.&lt;br /&gt;
*They are validated by experience and discussion.&lt;br /&gt;
*They consume more memory because of generalized format.&lt;br /&gt;
*They are optimized to store any kind of data. This can degrade performance.&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
2. http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;br /&gt;
http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance/&amp;lt;br&amp;gt;&lt;br /&gt;
http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.kuro5hin.org/story/2002/7/14/81923/3656&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.palserv.com/dp/DesignPatternsOverview.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71230</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71230"/>
		<updated>2012-11-24T17:15:47Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* See Also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;ref&amp;gt;http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type&amp;lt;ref&amp;gt;http://www.fatagnus.com/program-to-an-interface-not-an-implementation/&amp;lt;/ref&amp;gt; &amp;lt;ref&amp;gt;http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;/ref&amp;gt;. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&amp;lt;ref&amp;gt;http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
An example why we have to program to an interface is shown below:&lt;br /&gt;
&amp;lt;pre&amp;gt;   &lt;br /&gt;
public ProcessedBeans processBeans(Beans beans){&lt;br /&gt;
    ProcessedBeans processedBeans = beans.getProcessedBeans();  &lt;br /&gt;
    return processedBeans;  &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above code, we are programming for an implementation assuming that beans is the only item that needs processing. But, as we know, this is not the case. We have to process other food items as well before consumption. Due to the way we have programmed it now we will have to add many more functions for each type of food item that needs processing. This can be avoided, however, by programming to an interface.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public ProcessedFood processFood(FoodItem foodItem){  &lt;br /&gt;
    ProcessedFood processedFood = foodItem.getProcessedItem();  &lt;br /&gt;
    return processedFood;&lt;br /&gt;
}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By doing so, we have eliminated the need to add new functions for each food type as already noted. The UML diagram for the interface would look something like this:-&lt;br /&gt;
&lt;br /&gt;
[[File:UML-Program_to_an_Interface.png]]&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
Inheritance is good to represent ''is-a'' relationships but is not suitable for portraying ''has-a'' relationships. Many relationships between classes or components do not fall into the ''is-a'' category. (for example, a Car class is likely not a HashMap, but it may have a HashMap). In these scenarios it follows the composition is a better idea for modeling relationships between classes rather than inheritance.&lt;br /&gt;
&lt;br /&gt;
Below is one simple example where composition is much suited than inheritance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Flight extends Journey {...}&lt;br /&gt;
Class Bus extends Journey {...}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, instead of having a sub-class for Flight, class Journey can have a new field which is TransportMode which represents different modes of transport such as flight, bus, train etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class TransportMode {&lt;br /&gt;
  TransportType type;&lt;br /&gt;
  double getCost(double distance) {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  TransportMode mode;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  double getCost() { mode.getCost( getDistance() ) }&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However this is not to say that inheritance should not be used at all. Below is another example which shows that inheritance is the one which we should be using. Here the Human class represents a ''is-a'' relationship with Animal class which is quite natural and the proper way to look at the classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Animal {&lt;br /&gt;
    private String name;&lt;br /&gt;
    public String getName(){&lt;br /&gt;
        return name;&lt;br /&gt;
    }&lt;br /&gt;
    abstract String isIntelligent();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Cat extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;No&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Human extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;Yes&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In short, one should use inheritance for behavioral purposes ie., subclasses should override methods to specialize the behavior of the method and the object itself.&lt;br /&gt;
&lt;br /&gt;
'''Benefits of object composition'''&amp;lt;br&amp;gt;&lt;br /&gt;
* To favour composition over inheritance is a design principle that gives the design higher flexibility.&lt;br /&gt;
* Initial design becomes simple by avoiding hierarchical relationship among classes via inheritance and by identifying object behaviors in separate interfaces. &lt;br /&gt;
* Can easily accommodate future requirements without having to restructure large portions of code.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;/ref&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* All of the methods provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods.&lt;br /&gt;
* In inheritance the derived class only need to implement methods whose behavior needs to be modified.. &lt;br /&gt;
* Significantly less programming effort if only a handful of functions in the superclass needs to be overridden in the subclass.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
The key to identifying what should be variable lies in anticipating new requirements and changes to the existing requirements. The system must be designed in such a way so that it can evolve accordingly. Designing a robust system is we must take into account unforeseen changes to avoid a major design overhaul in future. Those changes might involve class redefinition and re-implementation, client modification, and retesting.Redesign affects many parts of the software system, and unanticipated changes are invariably expensive.&lt;br /&gt;
&lt;br /&gt;
Design patterns help you avoid this by ensuring that a system can change in specific ways. Each design pattern lets some aspect of system structure vary independently of other aspects, thereby making a system more robust to a particular kind of change.&lt;br /&gt;
&lt;br /&gt;
Below are some common causes of redesign along with the design pattern(s) that address them:&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Creating an object by specifying a class explicitly:''' Specifying a class name when you create an object commits you to a particular implementation instead of a particular interface. This commitment can complicate future changes. To avoid it, create objects indirectly.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Factory_method_pattern Factory Method], [http://en.wikipedia.org/wiki/Prototype_pattern Prototype].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on specific operations:''' When you specify a particular operation, you commit to one way of satisfying a request. By avoiding hard-coded requests, you make it easier to change the way a request gets satisfied both at compile-time and at run-time.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on hardware and software platform:''' External operating system interfaces and application programming interfaces (APIs) are different on different hardware and software platforms. Software that depends on a particular platform will be harder to port to other platforms. It may even be difficult to keep it up to date on its native platform. It's important therefore to design your system to limit its platform dependencies.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on object representations or implementation:''' Clients that know how an object is represented, stored, located, or implemented might need to be changed when the object changes. Hiding this information from clients keeps changes from cascading.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Memento_pattern Memento], [http://en.wikipedia.org/wiki/Proxy_pattern Proxy].&lt;br /&gt;
&lt;br /&gt;
*'''Algorithmic dependencies:''' Algorithms are often extended, optimized, and replaced during development and reuse. Objects that depend on an algorithm will have to change when the algorithm changes. Therefore algorithms that are likely to change should be isolated.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Builder_pattern Builder], [http://en.wikipedia.org/wiki/Iterator_pattern Iterator], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy], [http://en.wikipedia.org/wiki/Template_method_pattern Template Method], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
*'''Tight coupling:''' Classes that are tightly coupled are hard to reuse in isolation, since they depend on each other. Tight coupling leads to monolithic systems, where you can't change or remove a class without understanding and changing many other classes. The system becomes a dense mass that's hard to learn, port, and maintain.Loose coupling increases the probability that a class can be reused by itself and that a system can be learned, ported, modified, and extended more easily. Design patterns use techniques such as abstract coupling and layering to promote loosely coupled systems.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command], [http://en.wikipedia.org/wiki/Facade_pattern Facade], [http://en.wikipedia.org/wiki/Mediator_pattern Mediator], [http://en.wikipedia.org/wiki/Observer_pattern Observer].&lt;br /&gt;
&lt;br /&gt;
*'''Extending functionality by subclassing:''' Customizing an object by subclassing often isn't easy. Every new class has a fixed implementation overhead (initialization, finalization, etc.). Defining a subclass also requires an in-depth understanding of the parent class. For example, &lt;br /&gt;
&lt;br /&gt;
  Overriding one operation might require overriding another. An overridden operation might be required &lt;br /&gt;
  to call an inherited operation. And subclassing can lead to an explosion of classes, because you might have to introduce&lt;br /&gt;
  many new subclasses for even a simple extension.&lt;br /&gt;
&lt;br /&gt;
Object composition in general and delegation in particular provide flexible alternatives to inheritance for combining behavior.   New functionality can be added to an application by composing existing objects in new ways rather than by defining new subclasses of existing classes. On the other hand, heavy use of object composition can make designs harder to understand. Many design patterns&lt;br /&gt;
produce designs in which you can introduce customized functionality just by defining one subclass and composing its instances with existing ones.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Composite_pattern Composite], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Observer_pattern Observer], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy].&lt;br /&gt;
&lt;br /&gt;
*'''Inability to alter classes conveniently:''' Sometimes you have to modify a class that can't be modified conveniently. Perhaps you need the source code and don't have it (as may be the case with a commercial class library). Or maybe any change would require modifying lots of existing subclasses. Design patterns offer ways to modify classes in such circumstances.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Adapter_pattern Adapter], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
These examples reflect the flexibility that design patterns can help you build into your software. How crucial such flexibility is depends on the kind of software you're building.&lt;br /&gt;
&lt;br /&gt;
'''Advantages:'''&lt;br /&gt;
*Enables large scale reuse of software.&lt;br /&gt;
*Helps in improving developer communication.&lt;br /&gt;
*Captures expert knowledge and design trade-offs and make expertise widely available&lt;br /&gt;
&lt;br /&gt;
'''Disadvantages:'''&lt;br /&gt;
*Does not lead to direct code reuse and is complex in nature.&lt;br /&gt;
*They are validated by experience and discussion.&lt;br /&gt;
*They consume more memory because of generalized format.&lt;br /&gt;
*They are optimized to store any kind of data. This can degrade performance.&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
2. http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;br /&gt;
http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance/&amp;lt;br&amp;gt;&lt;br /&gt;
http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.kuro5hin.org/story/2002/7/14/81923/3656&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.palserv.com/dp/DesignPatternsOverview.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71229</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71229"/>
		<updated>2012-11-24T17:15:34Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;ref&amp;gt;http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type&amp;lt;ref&amp;gt;http://www.fatagnus.com/program-to-an-interface-not-an-implementation/&amp;lt;/ref&amp;gt; &amp;lt;ref&amp;gt;http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;/ref&amp;gt;. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&amp;lt;ref&amp;gt;http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
An example why we have to program to an interface is shown below:&lt;br /&gt;
&amp;lt;pre&amp;gt;   &lt;br /&gt;
public ProcessedBeans processBeans(Beans beans){&lt;br /&gt;
    ProcessedBeans processedBeans = beans.getProcessedBeans();  &lt;br /&gt;
    return processedBeans;  &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above code, we are programming for an implementation assuming that beans is the only item that needs processing. But, as we know, this is not the case. We have to process other food items as well before consumption. Due to the way we have programmed it now we will have to add many more functions for each type of food item that needs processing. This can be avoided, however, by programming to an interface.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public ProcessedFood processFood(FoodItem foodItem){  &lt;br /&gt;
    ProcessedFood processedFood = foodItem.getProcessedItem();  &lt;br /&gt;
    return processedFood;&lt;br /&gt;
}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By doing so, we have eliminated the need to add new functions for each food type as already noted. The UML diagram for the interface would look something like this:-&lt;br /&gt;
&lt;br /&gt;
[[File:UML-Program_to_an_Interface.png]]&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
Inheritance is good to represent ''is-a'' relationships but is not suitable for portraying ''has-a'' relationships. Many relationships between classes or components do not fall into the ''is-a'' category. (for example, a Car class is likely not a HashMap, but it may have a HashMap). In these scenarios it follows the composition is a better idea for modeling relationships between classes rather than inheritance.&lt;br /&gt;
&lt;br /&gt;
Below is one simple example where composition is much suited than inheritance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Flight extends Journey {...}&lt;br /&gt;
Class Bus extends Journey {...}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, instead of having a sub-class for Flight, class Journey can have a new field which is TransportMode which represents different modes of transport such as flight, bus, train etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class TransportMode {&lt;br /&gt;
  TransportType type;&lt;br /&gt;
  double getCost(double distance) {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  TransportMode mode;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  double getCost() { mode.getCost( getDistance() ) }&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However this is not to say that inheritance should not be used at all. Below is another example which shows that inheritance is the one which we should be using. Here the Human class represents a ''is-a'' relationship with Animal class which is quite natural and the proper way to look at the classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Animal {&lt;br /&gt;
    private String name;&lt;br /&gt;
    public String getName(){&lt;br /&gt;
        return name;&lt;br /&gt;
    }&lt;br /&gt;
    abstract String isIntelligent();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Cat extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;No&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Human extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;Yes&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In short, one should use inheritance for behavioral purposes ie., subclasses should override methods to specialize the behavior of the method and the object itself.&lt;br /&gt;
&lt;br /&gt;
'''Benefits of object composition'''&amp;lt;br&amp;gt;&lt;br /&gt;
* To favour composition over inheritance is a design principle that gives the design higher flexibility.&lt;br /&gt;
* Initial design becomes simple by avoiding hierarchical relationship among classes via inheritance and by identifying object behaviors in separate interfaces. &lt;br /&gt;
* Can easily accommodate future requirements without having to restructure large portions of code.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;/ref&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
* All of the methods provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods.&lt;br /&gt;
* In inheritance the derived class only need to implement methods whose behavior needs to be modified.. &lt;br /&gt;
* Significantly less programming effort if only a handful of functions in the superclass needs to be overridden in the subclass.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
The key to identifying what should be variable lies in anticipating new requirements and changes to the existing requirements. The system must be designed in such a way so that it can evolve accordingly. Designing a robust system is we must take into account unforeseen changes to avoid a major design overhaul in future. Those changes might involve class redefinition and re-implementation, client modification, and retesting.Redesign affects many parts of the software system, and unanticipated changes are invariably expensive.&lt;br /&gt;
&lt;br /&gt;
Design patterns help you avoid this by ensuring that a system can change in specific ways. Each design pattern lets some aspect of system structure vary independently of other aspects, thereby making a system more robust to a particular kind of change.&lt;br /&gt;
&lt;br /&gt;
Below are some common causes of redesign along with the design pattern(s) that address them:&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Creating an object by specifying a class explicitly:''' Specifying a class name when you create an object commits you to a particular implementation instead of a particular interface. This commitment can complicate future changes. To avoid it, create objects indirectly.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Factory_method_pattern Factory Method], [http://en.wikipedia.org/wiki/Prototype_pattern Prototype].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on specific operations:''' When you specify a particular operation, you commit to one way of satisfying a request. By avoiding hard-coded requests, you make it easier to change the way a request gets satisfied both at compile-time and at run-time.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on hardware and software platform:''' External operating system interfaces and application programming interfaces (APIs) are different on different hardware and software platforms. Software that depends on a particular platform will be harder to port to other platforms. It may even be difficult to keep it up to date on its native platform. It's important therefore to design your system to limit its platform dependencies.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on object representations or implementation:''' Clients that know how an object is represented, stored, located, or implemented might need to be changed when the object changes. Hiding this information from clients keeps changes from cascading.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Memento_pattern Memento], [http://en.wikipedia.org/wiki/Proxy_pattern Proxy].&lt;br /&gt;
&lt;br /&gt;
*'''Algorithmic dependencies:''' Algorithms are often extended, optimized, and replaced during development and reuse. Objects that depend on an algorithm will have to change when the algorithm changes. Therefore algorithms that are likely to change should be isolated.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Builder_pattern Builder], [http://en.wikipedia.org/wiki/Iterator_pattern Iterator], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy], [http://en.wikipedia.org/wiki/Template_method_pattern Template Method], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
*'''Tight coupling:''' Classes that are tightly coupled are hard to reuse in isolation, since they depend on each other. Tight coupling leads to monolithic systems, where you can't change or remove a class without understanding and changing many other classes. The system becomes a dense mass that's hard to learn, port, and maintain.Loose coupling increases the probability that a class can be reused by itself and that a system can be learned, ported, modified, and extended more easily. Design patterns use techniques such as abstract coupling and layering to promote loosely coupled systems.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command], [http://en.wikipedia.org/wiki/Facade_pattern Facade], [http://en.wikipedia.org/wiki/Mediator_pattern Mediator], [http://en.wikipedia.org/wiki/Observer_pattern Observer].&lt;br /&gt;
&lt;br /&gt;
*'''Extending functionality by subclassing:''' Customizing an object by subclassing often isn't easy. Every new class has a fixed implementation overhead (initialization, finalization, etc.). Defining a subclass also requires an in-depth understanding of the parent class. For example, &lt;br /&gt;
&lt;br /&gt;
  Overriding one operation might require overriding another. An overridden operation might be required &lt;br /&gt;
  to call an inherited operation. And subclassing can lead to an explosion of classes, because you might have to introduce&lt;br /&gt;
  many new subclasses for even a simple extension.&lt;br /&gt;
&lt;br /&gt;
Object composition in general and delegation in particular provide flexible alternatives to inheritance for combining behavior.   New functionality can be added to an application by composing existing objects in new ways rather than by defining new subclasses of existing classes. On the other hand, heavy use of object composition can make designs harder to understand. Many design patterns&lt;br /&gt;
produce designs in which you can introduce customized functionality just by defining one subclass and composing its instances with existing ones.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Composite_pattern Composite], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Observer_pattern Observer], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy].&lt;br /&gt;
&lt;br /&gt;
*'''Inability to alter classes conveniently:''' Sometimes you have to modify a class that can't be modified conveniently. Perhaps you need the source code and don't have it (as may be the case with a commercial class library). Or maybe any change would require modifying lots of existing subclasses. Design patterns offer ways to modify classes in such circumstances.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Adapter_pattern Adapter], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
These examples reflect the flexibility that design patterns can help you build into your software. How crucial such flexibility is depends on the kind of software you're building.&lt;br /&gt;
&lt;br /&gt;
'''Advantages:'''&lt;br /&gt;
*Enables large scale reuse of software.&lt;br /&gt;
*Helps in improving developer communication.&lt;br /&gt;
*Captures expert knowledge and design trade-offs and make expertise widely available&lt;br /&gt;
&lt;br /&gt;
'''Disadvantages:'''&lt;br /&gt;
*Does not lead to direct code reuse and is complex in nature.&lt;br /&gt;
*They are validated by experience and discussion.&lt;br /&gt;
*They consume more memory because of generalized format.&lt;br /&gt;
*They are optimized to store any kind of data. This can degrade performance.&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&lt;br /&gt;
2. http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;br /&gt;
http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance/&amp;lt;br&amp;gt;&lt;br /&gt;
http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.kuro5hin.org/story/2002/7/14/81923/3656&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.palserv.com/dp/DesignPatternsOverview.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71228</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71228"/>
		<updated>2012-11-24T17:13:39Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;ref&amp;gt;http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type&amp;lt;ref&amp;gt;http://www.fatagnus.com/program-to-an-interface-not-an-implementation/&amp;lt;/ref&amp;gt; &amp;lt;ref&amp;gt;http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;/ref&amp;gt;. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&amp;lt;ref&amp;gt;http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
An example why we have to program to an interface is shown below:&lt;br /&gt;
&amp;lt;pre&amp;gt;   &lt;br /&gt;
public ProcessedBeans processBeans(Beans beans){&lt;br /&gt;
    ProcessedBeans processedBeans = beans.getProcessedBeans();  &lt;br /&gt;
    return processedBeans;  &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above code, we are programming for an implementation assuming that beans is the only item that needs processing. But, as we know, this is not the case. We have to process other food items as well before consumption. Due to the way we have programmed it now we will have to add many more functions for each type of food item that needs processing. This can be avoided, however, by programming to an interface.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public ProcessedFood processFood(FoodItem foodItem){  &lt;br /&gt;
    ProcessedFood processedFood = foodItem.getProcessedItem();  &lt;br /&gt;
    return processedFood;&lt;br /&gt;
}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By doing so, we have eliminated the need to add new functions for each food type as already noted. The UML diagram for the interface would look something like this:-&lt;br /&gt;
&lt;br /&gt;
[[File:UML-Program_to_an_Interface.png]]&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
Inheritance is good to represent ''is-a'' relationships but is not suitable for portraying ''has-a'' relationships. Many relationships between classes or components do not fall into the ''is-a'' category. (for example, a Car class is likely not a HashMap, but it may have a HashMap). In these scenarios it follows the composition is a better idea for modeling relationships between classes rather than inheritance.&lt;br /&gt;
&lt;br /&gt;
Below is one simple example where composition is much suited than inheritance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Flight extends Journey {...}&lt;br /&gt;
Class Bus extends Journey {...}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, instead of having a sub-class for Flight, class Journey can have a new field which is TransportMode which represents different modes of transport such as flight, bus, train etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class TransportMode {&lt;br /&gt;
  TransportType type;&lt;br /&gt;
  double getCost(double distance) {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  TransportMode mode;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  double getCost() { mode.getCost( getDistance() ) }&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However this is not to say that inheritance should not be used at all. Below is another example which shows that inheritance is the one which we should be using. Here the Human class represents a ''is-a'' relationship with Animal class which is quite natural and the proper way to look at the classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Animal {&lt;br /&gt;
    private String name;&lt;br /&gt;
    public String getName(){&lt;br /&gt;
        return name;&lt;br /&gt;
    }&lt;br /&gt;
    abstract String isIntelligent();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Cat extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;No&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Human extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;Yes&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In short, one should use inheritance for behavioral purposes ie., subclasses should override methods to specialize the behavior of the method and the object itself.&lt;br /&gt;
&lt;br /&gt;
'''Benefits of object composition'''&amp;lt;br&amp;gt;&lt;br /&gt;
* To favour composition over inheritance is a design principle that gives the design higher flexibility.&lt;br /&gt;
* Initial design becomes simple by avoiding hierarchical relationship among classes via inheritance and by identifying object behaviors in separate interfaces. &lt;br /&gt;
* Can easily accommodate future requirements without having to restructure large portions of code.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&amp;lt;br&amp;gt;&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;/ref&amp;gt;&lt;br /&gt;
* All of the methods provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods.&lt;br /&gt;
* In inheritance the derived class only need to implement methods whose behavior needs to be modified.. &lt;br /&gt;
* Significantly less programming effort if only a handful of functions in the superclass needs to be overridden in the subclass.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
The key to identifying what should be variable lies in anticipating new requirements and changes to the existing requirements. The system must be designed in such a way so that it can evolve accordingly. Designing a robust system is we must take into account unforeseen changes to avoid a major design overhaul in future. Those changes might involve class redefinition and re-implementation, client modification, and retesting.Redesign affects many parts of the software system, and unanticipated changes are invariably expensive.&lt;br /&gt;
&lt;br /&gt;
Design patterns help you avoid this by ensuring that a system can change in specific ways. Each design pattern lets some aspect of system structure vary independently of other aspects, thereby making a system more robust to a particular kind of change.&lt;br /&gt;
&lt;br /&gt;
Below are some common causes of redesign along with the design pattern(s) that address them:&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Creating an object by specifying a class explicitly:''' Specifying a class name when you create an object commits you to a particular implementation instead of a particular interface. This commitment can complicate future changes. To avoid it, create objects indirectly.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Factory_method_pattern Factory Method], [http://en.wikipedia.org/wiki/Prototype_pattern Prototype].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on specific operations:''' When you specify a particular operation, you commit to one way of satisfying a request. By avoiding hard-coded requests, you make it easier to change the way a request gets satisfied both at compile-time and at run-time.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on hardware and software platform:''' External operating system interfaces and application programming interfaces (APIs) are different on different hardware and software platforms. Software that depends on a particular platform will be harder to port to other platforms. It may even be difficult to keep it up to date on its native platform. It's important therefore to design your system to limit its platform dependencies.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on object representations or implementation:''' Clients that know how an object is represented, stored, located, or implemented might need to be changed when the object changes. Hiding this information from clients keeps changes from cascading.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Memento_pattern Memento], [http://en.wikipedia.org/wiki/Proxy_pattern Proxy].&lt;br /&gt;
&lt;br /&gt;
*'''Algorithmic dependencies:''' Algorithms are often extended, optimized, and replaced during development and reuse. Objects that depend on an algorithm will have to change when the algorithm changes. Therefore algorithms that are likely to change should be isolated.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Builder_pattern Builder], [http://en.wikipedia.org/wiki/Iterator_pattern Iterator], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy], [http://en.wikipedia.org/wiki/Template_method_pattern Template Method], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
*'''Tight coupling:''' Classes that are tightly coupled are hard to reuse in isolation, since they depend on each other. Tight coupling leads to monolithic systems, where you can't change or remove a class without understanding and changing many other classes. The system becomes a dense mass that's hard to learn, port, and maintain.Loose coupling increases the probability that a class can be reused by itself and that a system can be learned, ported, modified, and extended more easily. Design patterns use techniques such as abstract coupling and layering to promote loosely coupled systems.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command], [http://en.wikipedia.org/wiki/Facade_pattern Facade], [http://en.wikipedia.org/wiki/Mediator_pattern Mediator], [http://en.wikipedia.org/wiki/Observer_pattern Observer].&lt;br /&gt;
&lt;br /&gt;
*'''Extending functionality by subclassing:''' Customizing an object by subclassing often isn't easy. Every new class has a fixed implementation overhead (initialization, finalization, etc.). Defining a subclass also requires an in-depth understanding of the parent class. For example, &lt;br /&gt;
&lt;br /&gt;
  Overriding one operation might require overriding another. An overridden operation might be required &lt;br /&gt;
  to call an inherited operation. And subclassing can lead to an explosion of classes, because you might have to introduce&lt;br /&gt;
  many new subclasses for even a simple extension.&lt;br /&gt;
&lt;br /&gt;
Object composition in general and delegation in particular provide flexible alternatives to inheritance for combining behavior.   New functionality can be added to an application by composing existing objects in new ways rather than by defining new subclasses of existing classes. On the other hand, heavy use of object composition can make designs harder to understand. Many design patterns&lt;br /&gt;
produce designs in which you can introduce customized functionality just by defining one subclass and composing its instances with existing ones.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Composite_pattern Composite], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Observer_pattern Observer], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy].&lt;br /&gt;
&lt;br /&gt;
*'''Inability to alter classes conveniently:''' Sometimes you have to modify a class that can't be modified conveniently. Perhaps you need the source code and don't have it (as may be the case with a commercial class library). Or maybe any change would require modifying lots of existing subclasses. Design patterns offer ways to modify classes in such circumstances.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Adapter_pattern Adapter], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
These examples reflect the flexibility that design patterns can help you build into your software. How crucial such flexibility is depends on the kind of software you're building.&lt;br /&gt;
&lt;br /&gt;
'''Advantages:'''&lt;br /&gt;
*Enables large scale reuse of software.&lt;br /&gt;
*Helps in improving developer communication.&lt;br /&gt;
*Captures expert knowledge and design trade-offs and make expertise widely available&lt;br /&gt;
&lt;br /&gt;
'''Disadvantages:'''&lt;br /&gt;
*Does not lead to direct code reuse and is complex in nature.&lt;br /&gt;
*They are validated by experience and discussion.&lt;br /&gt;
*They consume more memory because of generalized format.&lt;br /&gt;
*They are optimized to store any kind of data. This can degrade performance.&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;br /&gt;
http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance/&amp;lt;br&amp;gt;&lt;br /&gt;
http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.kuro5hin.org/story/2002/7/14/81923/3656&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.palserv.com/dp/DesignPatternsOverview.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71227</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71227"/>
		<updated>2012-11-24T17:13:02Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;ref&amp;gt;http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type&amp;lt;ref&amp;gt;http://www.fatagnus.com/program-to-an-interface-not-an-implementation/&amp;lt;/ref&amp;gt; &amp;lt;ref&amp;gt;http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;/ref&amp;gt;. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&amp;lt;ref&amp;gt;http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
An example why we have to program to an interface is shown below:&lt;br /&gt;
&amp;lt;pre&amp;gt;   &lt;br /&gt;
public ProcessedBeans processBeans(Beans beans){&lt;br /&gt;
    ProcessedBeans processedBeans = beans.getProcessedBeans();  &lt;br /&gt;
    return processedBeans;  &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above code, we are programming for an implementation assuming that beans is the only item that needs processing. But, as we know, this is not the case. We have to process other food items as well before consumption. Due to the way we have programmed it now we will have to add many more functions for each type of food item that needs processing. This can be avoided, however, by programming to an interface.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public ProcessedFood processFood(FoodItem foodItem){  &lt;br /&gt;
    ProcessedFood processedFood = foodItem.getProcessedItem();  &lt;br /&gt;
    return processedFood;&lt;br /&gt;
}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By doing so, we have eliminated the need to add new functions for each food type as already noted. The UML diagram for the interface would look something like this:-&lt;br /&gt;
&lt;br /&gt;
[[File:UML-Program_to_an_Interface.png]]&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
Inheritance is good to represent ''is-a'' relationships but is not suitable for portraying ''has-a'' relationships. Many relationships between classes or components do not fall into the ''is-a'' category. (for example, a Car class is likely not a HashMap, but it may have a HashMap). In these scenarios it follows the composition is a better idea for modeling relationships between classes rather than inheritance.&lt;br /&gt;
&lt;br /&gt;
Below is one simple example where composition is much suited than inheritance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Flight extends Journey {...}&lt;br /&gt;
Class Bus extends Journey {...}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, instead of having a sub-class for Flight, class Journey can have a new field which is TransportMode which represents different modes of transport such as flight, bus, train etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class TransportMode {&lt;br /&gt;
  TransportType type;&lt;br /&gt;
  double getCost(double distance) {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  TransportMode mode;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  double getCost() { mode.getCost( getDistance() ) }&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However this is not to say that inheritance should not be used at all. Below is another example which shows that inheritance is the one which we should be using. Here the Human class represents a ''is-a'' relationship with Animal class which is quite natural and the proper way to look at the classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Animal {&lt;br /&gt;
    private String name;&lt;br /&gt;
    public String getName(){&lt;br /&gt;
        return name;&lt;br /&gt;
    }&lt;br /&gt;
    abstract String isIntelligent();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Cat extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;No&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Human extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;Yes&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In short, one should use inheritance for behavioral purposes ie., subclasses should override methods to specialize the behavior of the method and the object itself.&lt;br /&gt;
&lt;br /&gt;
'''Benefits of object composition'''&amp;lt;br&amp;gt;&lt;br /&gt;
* To favour composition over inheritance is a design principle that gives the design higher flexibility.&lt;br /&gt;
* Initial design becomes simple by avoiding hierarchical relationship among classes via inheritance and by identifying object behaviors in separate interfaces. &lt;br /&gt;
* Can easily accommodate future requirements without having to restructure large portions of code.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&amp;lt;br&amp;gt;&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;/ref&amp;gt;&lt;br /&gt;
* All of the methods provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods.&lt;br /&gt;
* In inheritance the derived class only need to implement methods whose behavior needs to be modified.. &lt;br /&gt;
* Significantly less programming effort if only a handful of functions in the superclass needs to be overridden in the subclass.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
The key to identifying what should be variable lies in anticipating new requirements and changes to the existing requirements. The system must be designed in such a way so that it can evolve accordingly. Designing a robust system is we must take into account unforeseen changes to avoid a major design overhaul in future. Those changes might involve class redefinition and re-implementation, client modification, and retesting.Redesign affects many parts of the software system, and unanticipated changes are invariably expensive.&lt;br /&gt;
&lt;br /&gt;
Design patterns help you avoid this by ensuring that a system can change in specific ways. Each design pattern lets some aspect of system structure vary independently of other aspects, thereby making a system more robust to a particular kind of change.&lt;br /&gt;
&lt;br /&gt;
Below are some common causes of redesign along with the design pattern(s) that address them:&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Creating an object by specifying a class explicitly:''' Specifying a class name when you create an object commits you to a particular implementation instead of a particular interface. This commitment can complicate future changes. To avoid it, create objects indirectly.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Factory_method_pattern Factory Method], [http://en.wikipedia.org/wiki/Prototype_pattern Prototype].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on specific operations:''' When you specify a particular operation, you commit to one way of satisfying a request. By avoiding hard-coded requests, you make it easier to change the way a request gets satisfied both at compile-time and at run-time.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on hardware and software platform:''' External operating system interfaces and application programming interfaces (APIs) are different on different hardware and software platforms. Software that depends on a particular platform will be harder to port to other platforms. It may even be difficult to keep it up to date on its native platform. It's important therefore to design your system to limit its platform dependencies.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on object representations or implementation:''' Clients that know how an object is represented, stored, located, or implemented might need to be changed when the object changes. Hiding this information from clients keeps changes from cascading.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Memento_pattern Memento], [http://en.wikipedia.org/wiki/Proxy_pattern Proxy].&lt;br /&gt;
&lt;br /&gt;
*'''Algorithmic dependencies:''' Algorithms are often extended, optimized, and replaced during development and reuse. Objects that depend on an algorithm will have to change when the algorithm changes. Therefore algorithms that are likely to change should be isolated.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Builder_pattern Builder], [http://en.wikipedia.org/wiki/Iterator_pattern Iterator], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy], [http://en.wikipedia.org/wiki/Template_method_pattern Template Method], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
*'''Tight coupling:''' Classes that are tightly coupled are hard to reuse in isolation, since they depend on each other. Tight coupling leads to monolithic systems, where you can't change or remove a class without understanding and changing many other classes. The system becomes a dense mass that's hard to learn, port, and maintain.Loose coupling increases the probability that a class can be reused by itself and that a system can be learned, ported, modified, and extended more easily. Design patterns use techniques such as abstract coupling and layering to promote loosely coupled systems.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command], [http://en.wikipedia.org/wiki/Facade_pattern Facade], [http://en.wikipedia.org/wiki/Mediator_pattern Mediator], [http://en.wikipedia.org/wiki/Observer_pattern Observer].&lt;br /&gt;
&lt;br /&gt;
*'''Extending functionality by subclassing:''' Customizing an object by subclassing often isn't easy. Every new class has a fixed implementation overhead (initialization, finalization, etc.). Defining a subclass also requires an in-depth understanding of the parent class. For example, &lt;br /&gt;
&lt;br /&gt;
  Overriding one operation might require overriding another. An overridden operation might be required &lt;br /&gt;
  to call an inherited operation. And subclassing can lead to an explosion of classes, because you might have to introduce&lt;br /&gt;
  many new subclasses for even a simple extension.&lt;br /&gt;
&lt;br /&gt;
Object composition in general and delegation in particular provide flexible alternatives to inheritance for combining behavior.   New functionality can be added to an application by composing existing objects in new ways rather than by defining new subclasses of existing classes. On the other hand, heavy use of object composition can make designs harder to understand. Many design patterns&lt;br /&gt;
produce designs in which you can introduce customized functionality just by defining one subclass and composing its instances with existing ones.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Composite_pattern Composite], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Observer_pattern Observer], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy].&lt;br /&gt;
&lt;br /&gt;
*'''Inability to alter classes conveniently:''' Sometimes you have to modify a class that can't be modified conveniently. Perhaps you need the source code and don't have it (as may be the case with a commercial class library). Or maybe any change would require modifying lots of existing subclasses. Design patterns offer ways to modify classes in such circumstances.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Adapter_pattern Adapter], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
These examples reflect the flexibility that design patterns can help you build into your software. How crucial such flexibility is depends on the kind of software you're building.&lt;br /&gt;
&lt;br /&gt;
'''Advantages:'''&lt;br /&gt;
*Enables large scale reuse of software.&lt;br /&gt;
*Helps in improving developer communication.&lt;br /&gt;
*Captures expert knowledge and design trade-offs and make expertise widely available&lt;br /&gt;
&lt;br /&gt;
'''Disadvantages:'''&lt;br /&gt;
*Does not lead to direct code reuse and is complex in nature.&lt;br /&gt;
*They are validated by experience and discussion.&lt;br /&gt;
*They consume more memory because of generalized format.&lt;br /&gt;
*They are optimized to store any kind of data. This can degrade performance.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;br /&gt;
http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance/&amp;lt;br&amp;gt;&lt;br /&gt;
http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.kuro5hin.org/story/2002/7/14/81923/3656&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.palserv.com/dp/DesignPatternsOverview.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71226</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71226"/>
		<updated>2012-11-24T17:08:59Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;ref&amp;gt;http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type&amp;lt;ref&amp;gt;http://www.fatagnus.com/program-to-an-interface-not-an-implementation/&amp;lt;/ref&amp;gt; &amp;lt;ref&amp;gt;http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;/ref&amp;gt;. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
An example why we have to program to an interface is shown below:&lt;br /&gt;
&amp;lt;pre&amp;gt;   &lt;br /&gt;
public ProcessedBeans processBeans(Beans beans){&lt;br /&gt;
    ProcessedBeans processedBeans = beans.getProcessedBeans();  &lt;br /&gt;
    return processedBeans;  &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above code, we are programming for an implementation assuming that beans is the only item that needs processing. But, as we know, this is not the case. We have to process other food items as well before consumption. Due to the way we have programmed it now we will have to add many more functions for each type of food item that needs processing. This can be avoided, however, by programming to an interface.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public ProcessedFood processFood(FoodItem foodItem){  &lt;br /&gt;
    ProcessedFood processedFood = foodItem.getProcessedItem();  &lt;br /&gt;
    return processedFood;&lt;br /&gt;
}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By doing so, we have eliminated the need to add new functions for each food type as already noted. The UML diagram for the interface would look something like this:-&lt;br /&gt;
&lt;br /&gt;
[[File:UML-Program_to_an_Interface.png]]&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
Inheritance is good to represent ''is-a'' relationships but is not suitable for portraying ''has-a'' relationships. Many relationships between classes or components do not fall into the ''is-a'' category. (for example, a Car class is likely not a HashMap, but it may have a HashMap). In these scenarios it follows the composition is a better idea for modeling relationships between classes rather than inheritance.&lt;br /&gt;
&lt;br /&gt;
Below is one simple example where composition is much suited than inheritance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Flight extends Journey {...}&lt;br /&gt;
Class Bus extends Journey {...}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, instead of having a sub-class for Flight, class Journey can have a new field which is TransportMode which represents different modes of transport such as flight, bus, train etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class TransportMode {&lt;br /&gt;
  TransportType type;&lt;br /&gt;
  double getCost(double distance) {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  TransportMode mode;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  double getCost() { mode.getCost( getDistance() ) }&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However this is not to say that inheritance should not be used at all. Below is another example which shows that inheritance is the one which we should be using. Here the Human class represents a ''is-a'' relationship with Animal class which is quite natural and the proper way to look at the classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Animal {&lt;br /&gt;
    private String name;&lt;br /&gt;
    public String getName(){&lt;br /&gt;
        return name;&lt;br /&gt;
    }&lt;br /&gt;
    abstract String isIntelligent();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Cat extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;No&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Human extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;Yes&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In short, one should use inheritance for behavioral purposes ie., subclasses should override methods to specialize the behavior of the method and the object itself.&lt;br /&gt;
&lt;br /&gt;
'''Benefits of object composition'''&amp;lt;br&amp;gt;&lt;br /&gt;
* To favour composition over inheritance is a design principle that gives the design higher flexibility.&lt;br /&gt;
* Initial design becomes simple by avoiding hierarchical relationship among classes via inheritance and by identifying object behaviors in separate interfaces. &lt;br /&gt;
* Can easily accommodate future requirements without having to restructure large portions of code.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&amp;lt;br&amp;gt;&lt;br /&gt;
* All of the methods provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods.&lt;br /&gt;
* In inheritance the derived class only need to implement methods whose behavior needs to be modified.. &lt;br /&gt;
* Significantly less programming effort if only a handful of functions in the superclass needs to be overridden in the subclass.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
The key to identifying what should be variable lies in anticipating new requirements and changes to the existing requirements. The system must be designed in such a way so that it can evolve accordingly. Designing a robust system is we must take into account unforeseen changes to avoid a major design overhaul in future. Those changes might involve class redefinition and re-implementation, client modification, and retesting.Redesign affects many parts of the software system, and unanticipated changes are invariably expensive.&lt;br /&gt;
&lt;br /&gt;
Design patterns help you avoid this by ensuring that a system can change in specific ways. Each design pattern lets some aspect of system structure vary independently of other aspects, thereby making a system more robust to a particular kind of change.&lt;br /&gt;
&lt;br /&gt;
Below are some common causes of redesign along with the design pattern(s) that address them:&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Creating an object by specifying a class explicitly:''' Specifying a class name when you create an object commits you to a particular implementation instead of a particular interface. This commitment can complicate future changes. To avoid it, create objects indirectly.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Factory_method_pattern Factory Method], [http://en.wikipedia.org/wiki/Prototype_pattern Prototype].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on specific operations:''' When you specify a particular operation, you commit to one way of satisfying a request. By avoiding hard-coded requests, you make it easier to change the way a request gets satisfied both at compile-time and at run-time.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on hardware and software platform:''' External operating system interfaces and application programming interfaces (APIs) are different on different hardware and software platforms. Software that depends on a particular platform will be harder to port to other platforms. It may even be difficult to keep it up to date on its native platform. It's important therefore to design your system to limit its platform dependencies.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on object representations or implementation:''' Clients that know how an object is represented, stored, located, or implemented might need to be changed when the object changes. Hiding this information from clients keeps changes from cascading.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Memento_pattern Memento], [http://en.wikipedia.org/wiki/Proxy_pattern Proxy].&lt;br /&gt;
&lt;br /&gt;
*'''Algorithmic dependencies:''' Algorithms are often extended, optimized, and replaced during development and reuse. Objects that depend on an algorithm will have to change when the algorithm changes. Therefore algorithms that are likely to change should be isolated.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Builder_pattern Builder], [http://en.wikipedia.org/wiki/Iterator_pattern Iterator], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy], [http://en.wikipedia.org/wiki/Template_method_pattern Template Method], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
*'''Tight coupling:''' Classes that are tightly coupled are hard to reuse in isolation, since they depend on each other. Tight coupling leads to monolithic systems, where you can't change or remove a class without understanding and changing many other classes. The system becomes a dense mass that's hard to learn, port, and maintain.Loose coupling increases the probability that a class can be reused by itself and that a system can be learned, ported, modified, and extended more easily. Design patterns use techniques such as abstract coupling and layering to promote loosely coupled systems.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command], [http://en.wikipedia.org/wiki/Facade_pattern Facade], [http://en.wikipedia.org/wiki/Mediator_pattern Mediator], [http://en.wikipedia.org/wiki/Observer_pattern Observer].&lt;br /&gt;
&lt;br /&gt;
*'''Extending functionality by subclassing:''' Customizing an object by subclassing often isn't easy. Every new class has a fixed implementation overhead (initialization, finalization, etc.). Defining a subclass also requires an in-depth understanding of the parent class. For example, &lt;br /&gt;
&lt;br /&gt;
  Overriding one operation might require overriding another. An overridden operation might be required &lt;br /&gt;
  to call an inherited operation. And subclassing can lead to an explosion of classes, because you might have to introduce&lt;br /&gt;
  many new subclasses for even a simple extension.&lt;br /&gt;
&lt;br /&gt;
Object composition in general and delegation in particular provide flexible alternatives to inheritance for combining behavior.   New functionality can be added to an application by composing existing objects in new ways rather than by defining new subclasses of existing classes. On the other hand, heavy use of object composition can make designs harder to understand. Many design patterns&lt;br /&gt;
produce designs in which you can introduce customized functionality just by defining one subclass and composing its instances with existing ones.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Composite_pattern Composite], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Observer_pattern Observer], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy].&lt;br /&gt;
&lt;br /&gt;
*'''Inability to alter classes conveniently:''' Sometimes you have to modify a class that can't be modified conveniently. Perhaps you need the source code and don't have it (as may be the case with a commercial class library). Or maybe any change would require modifying lots of existing subclasses. Design patterns offer ways to modify classes in such circumstances.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Adapter_pattern Adapter], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
These examples reflect the flexibility that design patterns can help you build into your software. How crucial such flexibility is depends on the kind of software you're building.&lt;br /&gt;
&lt;br /&gt;
'''Advantages:'''&lt;br /&gt;
*Enables large scale reuse of software.&lt;br /&gt;
*Helps in improving developer communication.&lt;br /&gt;
*Captures expert knowledge and design trade-offs and make expertise widely available&lt;br /&gt;
&lt;br /&gt;
'''Disadvantages:'''&lt;br /&gt;
*Does not lead to direct code reuse and is complex in nature.&lt;br /&gt;
*They are validated by experience and discussion.&lt;br /&gt;
*They consume more memory because of generalized format.&lt;br /&gt;
*They are optimized to store any kind of data. This can degrade performance.&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;br /&gt;
http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance/&amp;lt;br&amp;gt;&lt;br /&gt;
http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.kuro5hin.org/story/2002/7/14/81923/3656&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.palserv.com/dp/DesignPatternsOverview.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71225</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71225"/>
		<updated>2012-11-24T17:08:27Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;ref&amp;gt;http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type&amp;lt;ref&amp;gt;http://www.fatagnus.com/program-to-an-interface-not-an-implementation/&amp;lt;/ref&amp;gt; &amp;lt;ref&amp;gt;http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;/ref&amp;gt;. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
An example why we have to program to an interface is shown below:&lt;br /&gt;
&amp;lt;pre&amp;gt;   &lt;br /&gt;
public ProcessedBeans processBeans(Beans beans){&lt;br /&gt;
    ProcessedBeans processedBeans = beans.getProcessedBeans();  &lt;br /&gt;
    return processedBeans;  &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above code, we are programming for an implementation assuming that beans is the only item that needs processing. But, as we know, this is not the case. We have to process other food items as well before consumption. Due to the way we have programmed it now we will have to add many more functions for each type of food item that needs processing. This can be avoided, however, by programming to an interface.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public ProcessedFood processFood(FoodItem foodItem){  &lt;br /&gt;
    ProcessedFood processedFood = foodItem.getProcessedItem();  &lt;br /&gt;
    return processedFood;&lt;br /&gt;
}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By doing so, we have eliminated the need to add new functions for each food type as already noted. The UML diagram for the interface would look something like this:-&lt;br /&gt;
&lt;br /&gt;
[[File:UML-Program_to_an_Interface.png]]&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
Inheritance is good to represent ''is-a'' relationships but is not suitable for portraying ''has-a'' relationships. Many relationships between classes or components do not fall into the ''is-a'' category. (for example, a Car class is likely not a HashMap, but it may have a HashMap). In these scenarios it follows the composition is a better idea for modeling relationships between classes rather than inheritance.&lt;br /&gt;
&lt;br /&gt;
Below is one simple example where composition is much suited than inheritance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Flight extends Journey {...}&lt;br /&gt;
Class Bus extends Journey {...}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, instead of having a sub-class for Flight, class Journey can have a new field which is TransportMode which represents different modes of transport such as flight, bus, train etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class TransportMode {&lt;br /&gt;
  TransportType type;&lt;br /&gt;
  double getCost(double distance) {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  TransportMode mode;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  double getCost() { mode.getCost( getDistance() ) }&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However this is not to say that inheritance should not be used at all. Below is another example which shows that inheritance is the one which we should be using. Here the Human class represents a ''is-a'' relationship with Animal class which is quite natural and the proper way to look at the classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Animal {&lt;br /&gt;
    private String name;&lt;br /&gt;
    public String getName(){&lt;br /&gt;
        return name;&lt;br /&gt;
    }&lt;br /&gt;
    abstract String isIntelligent();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Cat extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;No&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Human extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;Yes&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In short, one should use inheritance for behavioral purposes ie., subclasses should override methods to specialize the behavior of the method and the object itself.&lt;br /&gt;
&lt;br /&gt;
'''Benefits of object composition'''&amp;lt;br&amp;gt;&lt;br /&gt;
* To favour composition over inheritance is a design principle that gives the design higher flexibility.&lt;br /&gt;
* Initial design becomes simple by avoiding hierarchical relationship among classes via inheritance and by identifying object behaviors in separate interfaces. &lt;br /&gt;
* Can easily accommodate future requirements without having to restructure large portions of code.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&amp;lt;br&amp;gt;&lt;br /&gt;
* All of the methods provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods.&lt;br /&gt;
* In inheritance the derived class only need to implement methods whose behavior needs to be modified.. &lt;br /&gt;
* Significantly less programming effort if only a handful of functions in the superclass needs to be overridden in the subclass.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
The key to identifying what should be variable lies in anticipating new requirements and changes to the existing requirements. The system must be designed in such a way so that it can evolve accordingly. Designing a robust system is we must take into account unforeseen changes to avoid a major design overhaul in future. Those changes might involve class redefinition and re-implementation, client modification, and retesting.Redesign affects many parts of the software system, and unanticipated changes are invariably expensive.&lt;br /&gt;
&lt;br /&gt;
Design patterns help you avoid this by ensuring that a system can change in specific ways. Each design pattern lets some aspect of system structure vary independently of other aspects, thereby making a system more robust to a particular kind of change.&lt;br /&gt;
&lt;br /&gt;
Below are some common causes of redesign along with the design pattern(s) that address them:&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Creating an object by specifying a class explicitly:''' Specifying a class name when you create an object commits you to a particular implementation instead of a particular interface. This commitment can complicate future changes. To avoid it, create objects indirectly.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Factory_method_pattern Factory Method], [http://en.wikipedia.org/wiki/Prototype_pattern Prototype].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on specific operations:''' When you specify a particular operation, you commit to one way of satisfying a request. By avoiding hard-coded requests, you make it easier to change the way a request gets satisfied both at compile-time and at run-time.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on hardware and software platform:''' External operating system interfaces and application programming interfaces (APIs) are different on different hardware and software platforms. Software that depends on a particular platform will be harder to port to other platforms. It may even be difficult to keep it up to date on its native platform. It's important therefore to design your system to limit its platform dependencies.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on object representations or implementation:''' Clients that know how an object is represented, stored, located, or implemented might need to be changed when the object changes. Hiding this information from clients keeps changes from cascading.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Memento_pattern Memento], [http://en.wikipedia.org/wiki/Proxy_pattern Proxy].&lt;br /&gt;
&lt;br /&gt;
*'''Algorithmic dependencies:''' Algorithms are often extended, optimized, and replaced during development and reuse. Objects that depend on an algorithm will have to change when the algorithm changes. Therefore algorithms that are likely to change should be isolated.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Builder_pattern Builder], [http://en.wikipedia.org/wiki/Iterator_pattern Iterator], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy], [http://en.wikipedia.org/wiki/Template_method_pattern Template Method], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
*'''Tight coupling:''' Classes that are tightly coupled are hard to reuse in isolation, since they depend on each other. Tight coupling leads to monolithic systems, where you can't change or remove a class without understanding and changing many other classes. The system becomes a dense mass that's hard to learn, port, and maintain.Loose coupling increases the probability that a class can be reused by itself and that a system can be learned, ported, modified, and extended more easily. Design patterns use techniques such as abstract coupling and layering to promote loosely coupled systems.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command], [http://en.wikipedia.org/wiki/Facade_pattern Facade], [http://en.wikipedia.org/wiki/Mediator_pattern Mediator], [http://en.wikipedia.org/wiki/Observer_pattern Observer].&lt;br /&gt;
&lt;br /&gt;
*'''Extending functionality by subclassing:''' Customizing an object by subclassing often isn't easy. Every new class has a fixed implementation overhead (initialization, finalization, etc.). Defining a subclass also requires an in-depth understanding of the parent class. For example, &lt;br /&gt;
&lt;br /&gt;
  Overriding one operation might require overriding another. An overridden operation might be required &lt;br /&gt;
  to call an inherited operation. And subclassing can lead to an explosion of classes, because you might have to introduce&lt;br /&gt;
  many new subclasses for even a simple extension.&lt;br /&gt;
&lt;br /&gt;
Object composition in general and delegation in particular provide flexible alternatives to inheritance for combining behavior.   New functionality can be added to an application by composing existing objects in new ways rather than by defining new subclasses of existing classes. On the other hand, heavy use of object composition can make designs harder to understand. Many design patterns&lt;br /&gt;
produce designs in which you can introduce customized functionality just by defining one subclass and composing its instances with existing ones.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Composite_pattern Composite], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Observer_pattern Observer], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy].&lt;br /&gt;
&lt;br /&gt;
*'''Inability to alter classes conveniently:''' Sometimes you have to modify a class that can't be modified conveniently. Perhaps you need the source code and don't have it (as may be the case with a commercial class library). Or maybe any change would require modifying lots of existing subclasses. Design patterns offer ways to modify classes in such circumstances.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Adapter_pattern Adapter], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
These examples reflect the flexibility that design patterns can help you build into your software. How crucial such flexibility is depends on the kind of software you're building.&lt;br /&gt;
&lt;br /&gt;
'''Advantages:'''&lt;br /&gt;
*Enables large scale reuse of software.&lt;br /&gt;
*Helps in improving developer communication.&lt;br /&gt;
*Captures expert knowledge and design trade-offs and make expertise widely available&lt;br /&gt;
&lt;br /&gt;
'''Disadvantages:'''&lt;br /&gt;
*Does not lead to direct code reuse and is complex in nature.&lt;br /&gt;
*They are validated by experience and discussion.&lt;br /&gt;
*They consume more memory because of generalized format.&lt;br /&gt;
*They are optimized to store any kind of data. This can degrade performance.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;br /&gt;
http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance/&amp;lt;br&amp;gt;&lt;br /&gt;
http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.kuro5hin.org/story/2002/7/14/81923/3656&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.palserv.com/dp/DesignPatternsOverview.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71224</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71224"/>
		<updated>2012-11-24T16:58:22Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;ref&amp;gt;http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type&amp;lt;ref&amp;gt;http://www.fatagnus.com/program-to-an-interface-not-an-implementation/&amp;lt;/ref&amp;gt; &amp;lt;ref&amp;gt;http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;/ref&amp;gt;. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
An example why we have to program to an interface is shown below:&lt;br /&gt;
&amp;lt;pre&amp;gt;   &lt;br /&gt;
public ProcessedBeans processBeans(Beans beans){&lt;br /&gt;
    ProcessedBeans processedBeans = beans.getProcessedBeans();  &lt;br /&gt;
    return processedBeans;  &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above code, we are programming for an implementation assuming that beans is the only item that needs processing. But, as we know, this is not the case. We have to process other food items as well before consumption. Due to the way we have programmed it now we will have to add many more functions for each type of food item that needs processing. This can be avoided, however, by programming to an interface.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public ProcessedFood processFood(FoodItem foodItem){  &lt;br /&gt;
    ProcessedFood processedFood = foodItem.getProcessedItem();  &lt;br /&gt;
    return processedFood;&lt;br /&gt;
}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By doing so, we have eliminated the need to add new functions for each food type as already noted. The UML diagram for the interface would look something like this:-&lt;br /&gt;
&lt;br /&gt;
[[File:UML-Program_to_an_Interface.png]]&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
Inheritance is good to represent ''is-a'' relationships but is not suitable for portraying ''has-a'' relationships. Many relationships between classes or components do not fall into the ''is-a'' category. (for example, a Car class is likely not a HashMap, but it may have a HashMap). In these scenarios it follows the composition is a better idea for modeling relationships between classes rather than inheritance.&lt;br /&gt;
&lt;br /&gt;
Below is one simple example where composition is much suited than inheritance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Flight extends Journey {...}&lt;br /&gt;
Class Bus extends Journey {...}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, instead of having a sub-class for Flight, class Journey can have a new field which is TransportMode which represents different modes of transport such as flight, bus, train etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class TransportMode {&lt;br /&gt;
  TransportType type;&lt;br /&gt;
  double getCost(double distance) {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  TransportMode mode;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  double getCost() { mode.getCost( getDistance() ) }&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However this is not to say that inheritance should not be used at all. Below is another example which shows that inheritance is the one which we should be using. Here the Human class represents a ''is-a'' relationship with Animal class which is quite natural and the proper way to look at the classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Animal {&lt;br /&gt;
    private String name;&lt;br /&gt;
    public String getName(){&lt;br /&gt;
        return name;&lt;br /&gt;
    }&lt;br /&gt;
    abstract String isIntelligent();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Cat extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;No&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Human extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;Yes&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In short, one should use inheritance for behavioral purposes ie., subclasses should override methods to specialize the behavior of the method and the object itself.&lt;br /&gt;
&lt;br /&gt;
'''Benefits of object composition'''&amp;lt;br&amp;gt;&lt;br /&gt;
* To favour composition over inheritance is a design principle that gives the design higher flexibility.&lt;br /&gt;
* Initial design becomes simple by avoiding hierarchical relationship among classes via inheritance and by identifying object behaviors in separate interfaces. &lt;br /&gt;
* Can easily accommodate future requirements without having to restructure large portions of code.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&amp;lt;br&amp;gt;&lt;br /&gt;
* All of the methods provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods.&lt;br /&gt;
* In inheritance the derived class only need to implement methods whose behavior needs to be modified.. &lt;br /&gt;
* Significantly less programming effort if only a handful of functions in the superclass needs to be overridden in the subclass.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
The key to identifying what should be variable lies in anticipating new requirements and changes to the existing requirements. The system must be designed in such a way so that it can evolve accordingly. Designing a robust system is we must take into account unforeseen changes to avoid a major design overhaul in future. Those changes might involve class redefinition and re-implementation, client modification, and retesting.Redesign affects many parts of the software system, and unanticipated changes are invariably expensive.&lt;br /&gt;
&lt;br /&gt;
Design patterns help you avoid this by ensuring that a system can change in specific ways. Each design pattern lets some aspect of system structure vary independently of other aspects, thereby making a system more robust to a particular kind of change.&lt;br /&gt;
&lt;br /&gt;
Below are some common causes of redesign along with the design pattern(s) that address them:&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Creating an object by specifying a class explicitly:''' Specifying a class name when you create an object commits you to a particular implementation instead of a particular interface. This commitment can complicate future changes. To avoid it, create objects indirectly.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Factory_method_pattern Factory Method], [http://en.wikipedia.org/wiki/Prototype_pattern Prototype].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on specific operations:''' When you specify a particular operation, you commit to one way of satisfying a request. By avoiding hard-coded requests, you make it easier to change the way a request gets satisfied both at compile-time and at run-time.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on hardware and software platform:''' External operating system interfaces and application programming interfaces (APIs) are different on different hardware and software platforms. Software that depends on a particular platform will be harder to port to other platforms. It may even be difficult to keep it up to date on its native platform. It's important therefore to design your system to limit its platform dependencies.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on object representations or implementation:''' Clients that know how an object is represented, stored, located, or implemented might need to be changed when the object changes. Hiding this information from clients keeps changes from cascading.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Memento_pattern Memento], [http://en.wikipedia.org/wiki/Proxy_pattern Proxy].&lt;br /&gt;
&lt;br /&gt;
*'''Algorithmic dependencies:''' Algorithms are often extended, optimized, and replaced during development and reuse. Objects that depend on an algorithm will have to change when the algorithm changes. Therefore algorithms that are likely to change should be isolated.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Builder_pattern Builder], [http://en.wikipedia.org/wiki/Iterator_pattern Iterator], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy], [http://en.wikipedia.org/wiki/Template_method_pattern Template Method], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
*'''Tight coupling:''' Classes that are tightly coupled are hard to reuse in isolation, since they depend on each other. Tight coupling leads to monolithic systems, where you can't change or remove a class without understanding and changing many other classes. The system becomes a dense mass that's hard to learn, port, and maintain.Loose coupling increases the probability that a class can be reused by itself and that a system can be learned, ported, modified, and extended more easily. Design patterns use techniques such as abstract coupling and layering to promote loosely coupled systems.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command], [http://en.wikipedia.org/wiki/Facade_pattern Facade], [http://en.wikipedia.org/wiki/Mediator_pattern Mediator], [http://en.wikipedia.org/wiki/Observer_pattern Observer].&lt;br /&gt;
&lt;br /&gt;
*'''Extending functionality by subclassing:''' Customizing an object by subclassing often isn't easy. Every new class has a fixed implementation overhead (initialization, finalization, etc.). Defining a subclass also requires an in-depth understanding of the parent class. For example, &lt;br /&gt;
&lt;br /&gt;
  Overriding one operation might require overriding another. An overridden operation might be required &lt;br /&gt;
  to call an inherited operation. And subclassing can lead to an explosion of classes, because you might have to introduce&lt;br /&gt;
  many new subclasses for even a simple extension.&lt;br /&gt;
&lt;br /&gt;
Object composition in general and delegation in particular provide flexible alternatives to inheritance for combining behavior.   New functionality can be added to an application by composing existing objects in new ways rather than by defining new subclasses of existing classes. On the other hand, heavy use of object composition can make designs harder to understand. Many design patterns&lt;br /&gt;
produce designs in which you can introduce customized functionality just by defining one subclass and composing its instances with existing ones.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Composite_pattern Composite], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Observer_pattern Observer], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy].&lt;br /&gt;
&lt;br /&gt;
*'''Inability to alter classes conveniently:''' Sometimes you have to modify a class that can't be modified conveniently. Perhaps you need the source code and don't have it (as may be the case with a commercial class library). Or maybe any change would require modifying lots of existing subclasses. Design patterns offer ways to modify classes in such circumstances.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Adapter_pattern Adapter], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
These examples reflect the flexibility that design patterns can help you build into your software. How crucial such flexibility is depends on the kind of software you're building.&lt;br /&gt;
&lt;br /&gt;
'''Advantages:'''&lt;br /&gt;
*Enables large scale reuse of software.&lt;br /&gt;
*Helps in improving developer communication.&lt;br /&gt;
*Captures expert knowledge and design trade-offs and make expertise widely available&lt;br /&gt;
&lt;br /&gt;
'''Disadvantages:'''&lt;br /&gt;
*Does not lead to direct code reuse and is complex in nature.&lt;br /&gt;
*They are validated by experience and discussion.&lt;br /&gt;
*They consume more memory because of generalized format.&lt;br /&gt;
*They are optimized to store any kind of data. This can degrade performance.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;br /&gt;
http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance/&amp;lt;br&amp;gt;&lt;br /&gt;
http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.kuro5hin.org/story/2002/7/14/81923/3656&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.palserv.com/dp/DesignPatternsOverview.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71223</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=71223"/>
		<updated>2012-11-24T16:27:16Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;ref&amp;gt;http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;/ref&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
An example why we have to program to an interface is shown below:&lt;br /&gt;
&amp;lt;pre&amp;gt;   &lt;br /&gt;
public ProcessedBeans processBeans(Beans beans){&lt;br /&gt;
    ProcessedBeans processedBeans = beans.getProcessedBeans();  &lt;br /&gt;
    return processedBeans;  &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above code, we are programming for an implementation assuming that beans is the only item that needs processing. But, as we know, this is not the case. We have to process other food items as well before consumption. Due to the way we have programmed it now we will have to add many more functions for each type of food item that needs processing. This can be avoided, however, by programming to an interface.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public ProcessedFood processFood(FoodItem foodItem){  &lt;br /&gt;
    ProcessedFood processedFood = foodItem.getProcessedItem();  &lt;br /&gt;
    return processedFood;&lt;br /&gt;
}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By doing so, we have eliminated the need to add new functions for each food type as already noted. The UML diagram for the interface would look something like this:-&lt;br /&gt;
&lt;br /&gt;
[[File:UML-Program_to_an_Interface.png]]&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
Inheritance is good to represent ''is-a'' relationships but is not suitable for portraying ''has-a'' relationships. Many relationships between classes or components do not fall into the ''is-a'' category. (for example, a Car class is likely not a HashMap, but it may have a HashMap). In these scenarios it follows the composition is a better idea for modeling relationships between classes rather than inheritance.&lt;br /&gt;
&lt;br /&gt;
Below is one simple example where composition is much suited than inheritance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Flight extends Journey {...}&lt;br /&gt;
Class Bus extends Journey {...}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, instead of having a sub-class for Flight, class Journey can have a new field which is TransportMode which represents different modes of transport such as flight, bus, train etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class TransportMode {&lt;br /&gt;
  TransportType type;&lt;br /&gt;
  double getCost(double distance) {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  TransportMode mode;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  double getCost() { mode.getCost( getDistance() ) }&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However this is not to say that inheritance should not be used at all. Below is another example which shows that inheritance is the one which we should be using. Here the Human class represents a ''is-a'' relationship with Animal class which is quite natural and the proper way to look at the classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Animal {&lt;br /&gt;
    private String name;&lt;br /&gt;
    public String getName(){&lt;br /&gt;
        return name;&lt;br /&gt;
    }&lt;br /&gt;
    abstract String isIntelligent();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Cat extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;No&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Human extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;Yes&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In short, one should use inheritance for behavioral purposes ie., subclasses should override methods to specialize the behavior of the method and the object itself.&lt;br /&gt;
&lt;br /&gt;
'''Benefits of object composition'''&amp;lt;br&amp;gt;&lt;br /&gt;
* To favour composition over inheritance is a design principle that gives the design higher flexibility.&lt;br /&gt;
* Initial design becomes simple by avoiding hierarchical relationship among classes via inheritance and by identifying object behaviors in separate interfaces. &lt;br /&gt;
* Can easily accommodate future requirements without having to restructure large portions of code.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&amp;lt;br&amp;gt;&lt;br /&gt;
* All of the methods provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods.&lt;br /&gt;
* In inheritance the derived class only need to implement methods whose behavior needs to be modified.. &lt;br /&gt;
* Significantly less programming effort if only a handful of functions in the superclass needs to be overridden in the subclass.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
The key to identifying what should be variable lies in anticipating new requirements and changes to the existing requirements. The system must be designed in such a way so that it can evolve accordingly. Designing a robust system is we must take into account unforeseen changes to avoid a major design overhaul in future. Those changes might involve class redefinition and re-implementation, client modification, and retesting.Redesign affects many parts of the software system, and unanticipated changes are invariably expensive.&lt;br /&gt;
&lt;br /&gt;
Design patterns help you avoid this by ensuring that a system can change in specific ways. Each design pattern lets some aspect of system structure vary independently of other aspects, thereby making a system more robust to a particular kind of change.&lt;br /&gt;
&lt;br /&gt;
Below are some common causes of redesign along with the design pattern(s) that address them:&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Creating an object by specifying a class explicitly:''' Specifying a class name when you create an object commits you to a particular implementation instead of a particular interface. This commitment can complicate future changes. To avoid it, create objects indirectly.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Factory_method_pattern Factory Method], [http://en.wikipedia.org/wiki/Prototype_pattern Prototype].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on specific operations:''' When you specify a particular operation, you commit to one way of satisfying a request. By avoiding hard-coded requests, you make it easier to change the way a request gets satisfied both at compile-time and at run-time.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on hardware and software platform:''' External operating system interfaces and application programming interfaces (APIs) are different on different hardware and software platforms. Software that depends on a particular platform will be harder to port to other platforms. It may even be difficult to keep it up to date on its native platform. It's important therefore to design your system to limit its platform dependencies.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on object representations or implementation:''' Clients that know how an object is represented, stored, located, or implemented might need to be changed when the object changes. Hiding this information from clients keeps changes from cascading.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Memento_pattern Memento], [http://en.wikipedia.org/wiki/Proxy_pattern Proxy].&lt;br /&gt;
&lt;br /&gt;
*'''Algorithmic dependencies:''' Algorithms are often extended, optimized, and replaced during development and reuse. Objects that depend on an algorithm will have to change when the algorithm changes. Therefore algorithms that are likely to change should be isolated.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Builder_pattern Builder], [http://en.wikipedia.org/wiki/Iterator_pattern Iterator], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy], [http://en.wikipedia.org/wiki/Template_method_pattern Template Method], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
*'''Tight coupling:''' Classes that are tightly coupled are hard to reuse in isolation, since they depend on each other. Tight coupling leads to monolithic systems, where you can't change or remove a class without understanding and changing many other classes. The system becomes a dense mass that's hard to learn, port, and maintain.Loose coupling increases the probability that a class can be reused by itself and that a system can be learned, ported, modified, and extended more easily. Design patterns use techniques such as abstract coupling and layering to promote loosely coupled systems.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command], [http://en.wikipedia.org/wiki/Facade_pattern Facade], [http://en.wikipedia.org/wiki/Mediator_pattern Mediator], [http://en.wikipedia.org/wiki/Observer_pattern Observer].&lt;br /&gt;
&lt;br /&gt;
*'''Extending functionality by subclassing:''' Customizing an object by subclassing often isn't easy. Every new class has a fixed implementation overhead (initialization, finalization, etc.). Defining a subclass also requires an in-depth understanding of the parent class. For example, &lt;br /&gt;
&lt;br /&gt;
  Overriding one operation might require overriding another. An overridden operation might be required &lt;br /&gt;
  to call an inherited operation. And subclassing can lead to an explosion of classes, because you might have to introduce&lt;br /&gt;
  many new subclasses for even a simple extension.&lt;br /&gt;
&lt;br /&gt;
Object composition in general and delegation in particular provide flexible alternatives to inheritance for combining behavior.   New functionality can be added to an application by composing existing objects in new ways rather than by defining new subclasses of existing classes. On the other hand, heavy use of object composition can make designs harder to understand. Many design patterns&lt;br /&gt;
produce designs in which you can introduce customized functionality just by defining one subclass and composing its instances with existing ones.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Composite_pattern Composite], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Observer_pattern Observer], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy].&lt;br /&gt;
&lt;br /&gt;
*'''Inability to alter classes conveniently:''' Sometimes you have to modify a class that can't be modified conveniently. Perhaps you need the source code and don't have it (as may be the case with a commercial class library). Or maybe any change would require modifying lots of existing subclasses. Design patterns offer ways to modify classes in such circumstances.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Adapter_pattern Adapter], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
These examples reflect the flexibility that design patterns can help you build into your software. How crucial such flexibility is depends on the kind of software you're building.&lt;br /&gt;
&lt;br /&gt;
'''Advantages:'''&lt;br /&gt;
*Enables large scale reuse of software.&lt;br /&gt;
*Helps in improving developer communication.&lt;br /&gt;
*Captures expert knowledge and design trade-offs and make expertise widely available&lt;br /&gt;
&lt;br /&gt;
'''Disadvantages:'''&lt;br /&gt;
*Does not lead to direct code reuse and is complex in nature.&lt;br /&gt;
*They are validated by experience and discussion.&lt;br /&gt;
*They consume more memory because of generalized format.&lt;br /&gt;
*They are optimized to store any kind of data. This can degrade performance.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;br /&gt;
http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance/&amp;lt;br&amp;gt;&lt;br /&gt;
http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.kuro5hin.org/story/2002/7/14/81923/3656&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.palserv.com/dp/DesignPatternsOverview.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=70937</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=70937"/>
		<updated>2012-11-20T00:27:04Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Program to an interface, not an implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
An example why we have to program to an interface is shown below:&lt;br /&gt;
&amp;lt;pre&amp;gt;   &lt;br /&gt;
public ProcessedBeans processBeans(Beans beans){&lt;br /&gt;
    ProcessedBeans processedBeans = beans.getProcessedBeans();  &lt;br /&gt;
    return processedBeans;  &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above code, we are programming for an implementation assuming that beans is the only item that needs processing. But, as we know, this is not the case. We have to process other food items as well before consumption. Due to the way we have programmed it now we will have to add many more functions for each type of food item that needs processing. This can be avoided, however, by programming to an interface.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public ProcessedFood processFood(FoodItem foodItem){  &lt;br /&gt;
    ProcessedFood processedFood = foodItem.getProcessedItem();  &lt;br /&gt;
    return processedFood;&lt;br /&gt;
}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By doing so, we have eliminated the need to add new functions for each food type as already noted. The UML diagram for the interface would look something like this:-&lt;br /&gt;
&lt;br /&gt;
[[File:UML-Program_to_an_Interface.png]]&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
Inheritance is good to represent ''is-a'' relationships but is not suitable for portraying ''has-a'' relationships. Many relationships between classes or components do not fall into the ''is-a'' category. (for example, a Car class is likely not a HashMap, but it may have a HashMap). In these scenarios it follows the composition is a better idea for modeling relationships between classes rather than inheritance.&lt;br /&gt;
&lt;br /&gt;
Below is one simple example where composition is much suited than inheritance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Flight extends Journey {...}&lt;br /&gt;
Class Bus extends Journey {...}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, instead of having a sub-class for Flight, class Journey can have a new field which is TransportMode which represents different modes of transport such as flight, bus, train etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class TransportMode {&lt;br /&gt;
  TransportType type;&lt;br /&gt;
  double getCost(double distance) {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  TransportMode mode;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  double getCost() { mode.getCost( getDistance() ) }&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However this is not to say that inheritance should not be used at all. Below is another example which shows that inheritance is the one which we should be using. Here the Human class represents a ''is-a'' relationship with Animal class which is quite natural and the proper way to look at the classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Animal {&lt;br /&gt;
    private String name;&lt;br /&gt;
    public String getName(){&lt;br /&gt;
        return name;&lt;br /&gt;
    }&lt;br /&gt;
    abstract String isIntelligent();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Cat extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;No&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Human extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;Yes&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In short, one should use inheritance for behavioral purposes ie., subclasses should override methods to specialize the behavior of the method and the object itself.&lt;br /&gt;
&lt;br /&gt;
'''Benefits of object composition'''&amp;lt;br&amp;gt;&lt;br /&gt;
* To favour composition over inheritance is a design principle that gives the design higher flexibility.&lt;br /&gt;
* Initial design becomes simple by avoiding hierarchical relationship among classes via inheritance and by identifying object behaviors in separate interfaces. &lt;br /&gt;
* Can easily accommodate future requirements without having to restructure large portions of code.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&amp;lt;br&amp;gt;&lt;br /&gt;
* All of the methods provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods.&lt;br /&gt;
* In inheritance the derived class only need to implement methods whose behavior needs to be modified.. &lt;br /&gt;
* Significantly less programming effort if only a handful of functions in the superclass needs to be overridden in the subclass.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
The key to identifying what should be variable lies in anticipating new requirements and changes to the existing requirements. The system must be designed in such a way so that it can evolve accordingly. Designing a robust system is we must take into account unforeseen changes to avoid a major design overhaul in future. Those changes might involve class redefinition and re-implementation, client modification, and retesting.Redesign affects many parts of the software system, and unanticipated changes are invariably expensive.&lt;br /&gt;
&lt;br /&gt;
Design patterns help you avoid this by ensuring that a system can change in specific ways. Each design pattern lets some aspect of system structure vary independently of other aspects, thereby making a system more robust to a particular kind of change.&lt;br /&gt;
&lt;br /&gt;
Below are some common causes of redesign along with the design pattern(s) that address them:&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Creating an object by specifying a class explicitly:''' Specifying a class name when you create an object commits you to a particular implementation instead of a particular interface. This commitment can complicate future changes. To avoid it, create objects indirectly.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Factory_method_pattern Factory Method], [http://en.wikipedia.org/wiki/Prototype_pattern Prototype].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on specific operations:''' When you specify a particular operation, you commit to one way of satisfying a request. By avoiding hard-coded requests, you make it easier to change the way a request gets satisfied both at compile-time and at run-time.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on hardware and software platform:''' External operating system interfaces and application programming interfaces (APIs) are different on different hardware and software platforms. Software that depends on a particular platform will be harder to port to other platforms. It may even be difficult to keep it up to date on its native platform. It's important therefore to design your system to limit its platform dependencies.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on object representations or implementation:''' Clients that know how an object is represented, stored, located, or implemented might need to be changed when the object changes. Hiding this information from clients keeps changes from cascading.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Memento_pattern Memento], [http://en.wikipedia.org/wiki/Proxy_pattern Proxy].&lt;br /&gt;
&lt;br /&gt;
*'''Algorithmic dependencies:''' Algorithms are often extended, optimized, and replaced during development and reuse. Objects that depend on an algorithm will have to change when the algorithm changes. Therefore algorithms that are likely to change should be isolated.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Builder_pattern Builder], [http://en.wikipedia.org/wiki/Iterator_pattern Iterator], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy], [http://en.wikipedia.org/wiki/Template_method_pattern Template Method], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
*'''Tight coupling:''' Classes that are tightly coupled are hard to reuse in isolation, since they depend on each other. Tight coupling leads to monolithic systems, where you can't change or remove a class without understanding and changing many other classes. The system becomes a dense mass that's hard to learn, port, and maintain.Loose coupling increases the probability that a class can be reused by itself and that a system can be learned, ported, modified, and extended more easily. Design patterns use techniques such as abstract coupling and layering to promote loosely coupled systems.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command], [http://en.wikipedia.org/wiki/Facade_pattern Facade], [http://en.wikipedia.org/wiki/Mediator_pattern Mediator], [http://en.wikipedia.org/wiki/Observer_pattern Observer].&lt;br /&gt;
&lt;br /&gt;
*'''Extending functionality by subclassing:''' Customizing an object by subclassing often isn't easy. Every new class has a fixed implementation overhead (initialization, finalization, etc.). Defining a subclass also requires an in-depth understanding of the parent class. For example, &lt;br /&gt;
&lt;br /&gt;
  Overriding one operation might require overriding another. An overridden operation might be required &lt;br /&gt;
  to call an inherited operation. And subclassing can lead to an explosion of classes, because you might have to introduce&lt;br /&gt;
  many new subclasses for even a simple extension.&lt;br /&gt;
&lt;br /&gt;
Object composition in general and delegation in particular provide flexible alternatives to inheritance for combining behavior.   New functionality can be added to an application by composing existing objects in new ways rather than by defining new subclasses of existing classes. On the other hand, heavy use of object composition can make designs harder to understand. Many design patterns&lt;br /&gt;
produce designs in which you can introduce customized functionality just by defining one subclass and composing its instances with existing ones.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Composite_pattern Composite], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Observer_pattern Observer], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy].&lt;br /&gt;
&lt;br /&gt;
*'''Inability to alter classes conveniently:''' Sometimes you have to modify a class that can't be modified conveniently. Perhaps you need the source code and don't have it (as may be the case with a commercial class library). Or maybe any change would require modifying lots of existing subclasses. Design patterns offer ways to modify classes in such circumstances.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Adapter_pattern Adapter], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
These examples reflect the flexibility that design patterns can help you build into your software. How crucial such flexibility is depends on the kind of software you're building.&lt;br /&gt;
&lt;br /&gt;
'''Advantages:'''&lt;br /&gt;
*Enables large scale reuse of software.&lt;br /&gt;
*Helps in improving developer communication.&lt;br /&gt;
*Captures expert knowledge and design trade-offs and make expertise widely available&lt;br /&gt;
&lt;br /&gt;
'''Disadvantages:'''&lt;br /&gt;
*Does not lead to direct code reuse and is complex in nature.&lt;br /&gt;
*They are validated by experience and discussion.&lt;br /&gt;
*They consume more memory because of generalized format.&lt;br /&gt;
*They are optimized to store any kind of data. This can degrade performance.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;br /&gt;
http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance/&amp;lt;br&amp;gt;&lt;br /&gt;
http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.kuro5hin.org/story/2002/7/14/81923/3656&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.palserv.com/dp/DesignPatternsOverview.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:UML-Program_to_an_Interface.png&amp;diff=70934</id>
		<title>File:UML-Program to an Interface.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:UML-Program_to_an_Interface.png&amp;diff=70934"/>
		<updated>2012-11-20T00:25:49Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=70931</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=70931"/>
		<updated>2012-11-20T00:21:38Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Program to an interface, not an implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
An example why we have to program to an interface is shown below:&lt;br /&gt;
&amp;lt;pre&amp;gt;   &lt;br /&gt;
public ProcessedBeans processBeans(Beans beans){&lt;br /&gt;
    ProcessedBeans processedBeans = beans.getProcessedBeans();  &lt;br /&gt;
    return processedBeans;  &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above code, we are programming for an implementation assuming that beans is the only item that needs processing. But, as we know, this is not the case. We have to process other food items as well before consumption. Due to the way we have programmed it now we will have to add many more functions for each type of food item that needs processing. This can be avoided, however, by programming to an interface.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public ProcessedFood processFood(FoodItem foodItem){  &lt;br /&gt;
    ProcessedFood processedFood = foodItem.getProcessedItem();  &lt;br /&gt;
    return processedFood;&lt;br /&gt;
}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By doing so, we have eliminated the need to add new functions for each food type as already noted. The UML diagram for the interface would look something like this:-&lt;br /&gt;
&lt;br /&gt;
[[File:UML-Program_to_an_Interface.jpg]]&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
Inheritance is good to represent ''is-a'' relationships but is not suitable for portraying ''has-a'' relationships. Many relationships between classes or components do not fall into the ''is-a'' category. (for example, a Car class is likely not a HashMap, but it may have a HashMap). In these scenarios it follows the composition is a better idea for modeling relationships between classes rather than inheritance.&lt;br /&gt;
&lt;br /&gt;
Below is one simple example where composition is much suited than inheritance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Flight extends Journey {...}&lt;br /&gt;
Class Bus extends Journey {...}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, instead of having a sub-class for Flight, class Journey can have a new field which is TransportMode which represents different modes of transport such as flight, bus, train etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class TransportMode {&lt;br /&gt;
  TransportType type;&lt;br /&gt;
  double getCost(double distance) {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  TransportMode mode;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  double getCost() { mode.getCost( getDistance() ) }&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However this is not to say that inheritance should not be used at all. Below is another example which shows that inheritance is the one which we should be using. Here the Human class represents a ''is-a'' relationship with Animal class which is quite natural and the proper way to look at the classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Animal {&lt;br /&gt;
    private String name;&lt;br /&gt;
    public String getName(){&lt;br /&gt;
        return name;&lt;br /&gt;
    }&lt;br /&gt;
    abstract String isIntelligent();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Cat extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;No&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Human extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;Yes&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In short, one should use inheritance for behavioral purposes ie., subclasses should override methods to specialize the behavior of the method and the object itself.&lt;br /&gt;
&lt;br /&gt;
'''Benefits of object composition'''&amp;lt;br&amp;gt;&lt;br /&gt;
* To favour composition over inheritance is a design principle that gives the design higher flexibility.&lt;br /&gt;
* Initial design becomes simple by avoiding hierarchical relationship among classes via inheritance and by identifying object behaviors in separate interfaces. &lt;br /&gt;
* Can easily accommodate future requirements without having to restructure large portions of code.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&amp;lt;br&amp;gt;&lt;br /&gt;
* All of the methods provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods.&lt;br /&gt;
* In inheritance the derived class only need to implement methods whose behavior needs to be modified.. &lt;br /&gt;
* Significantly less programming effort if only a handful of functions in the superclass needs to be overridden in the subclass.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
The key to identifying what should be variable lies in anticipating new requirements and changes to the existing requirements. The system must be designed in such a way so that it can evolve accordingly. Designing a robust system is we must take into account unforeseen changes to avoid a major design overhaul in future. Those changes might involve class redefinition and re-implementation, client modification, and retesting.Redesign affects many parts of the software system, and unanticipated changes are invariably expensive.&lt;br /&gt;
&lt;br /&gt;
Design patterns help you avoid this by ensuring that a system can change in specific ways. Each design pattern lets some aspect of system structure vary independently of other aspects, thereby making a system more robust to a particular kind of change.&lt;br /&gt;
&lt;br /&gt;
Below are some common causes of redesign along with the design pattern(s) that address them:&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Creating an object by specifying a class explicitly:''' Specifying a class name when you create an object commits you to a particular implementation instead of a particular interface. This commitment can complicate future changes. To avoid it, create objects indirectly.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Factory_method_pattern Factory Method], [http://en.wikipedia.org/wiki/Prototype_pattern Prototype].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on specific operations:''' When you specify a particular operation, you commit to one way of satisfying a request. By avoiding hard-coded requests, you make it easier to change the way a request gets satisfied both at compile-time and at run-time.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on hardware and software platform:''' External operating system interfaces and application programming interfaces (APIs) are different on different hardware and software platforms. Software that depends on a particular platform will be harder to port to other platforms. It may even be difficult to keep it up to date on its native platform. It's important therefore to design your system to limit its platform dependencies.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on object representations or implementation:''' Clients that know how an object is represented, stored, located, or implemented might need to be changed when the object changes. Hiding this information from clients keeps changes from cascading.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Memento_pattern Memento], [http://en.wikipedia.org/wiki/Proxy_pattern Proxy].&lt;br /&gt;
&lt;br /&gt;
*'''Algorithmic dependencies:''' Algorithms are often extended, optimized, and replaced during development and reuse. Objects that depend on an algorithm will have to change when the algorithm changes. Therefore algorithms that are likely to change should be isolated.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Builder_pattern Builder], [http://en.wikipedia.org/wiki/Iterator_pattern Iterator], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy], [http://en.wikipedia.org/wiki/Template_method_pattern Template Method], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
*'''Tight coupling:''' Classes that are tightly coupled are hard to reuse in isolation, since they depend on each other. Tight coupling leads to monolithic systems, where you can't change or remove a class without understanding and changing many other classes. The system becomes a dense mass that's hard to learn, port, and maintain.Loose coupling increases the probability that a class can be reused by itself and that a system can be learned, ported, modified, and extended more easily. Design patterns use techniques such as abstract coupling and layering to promote loosely coupled systems.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command], [http://en.wikipedia.org/wiki/Facade_pattern Facade], [http://en.wikipedia.org/wiki/Mediator_pattern Mediator], [http://en.wikipedia.org/wiki/Observer_pattern Observer].&lt;br /&gt;
&lt;br /&gt;
*'''Extending functionality by subclassing:''' Customizing an object by subclassing often isn't easy. Every new class has a fixed implementation overhead (initialization, finalization, etc.). Defining a subclass also requires an in-depth understanding of the parent class. For example, &lt;br /&gt;
&lt;br /&gt;
  Overriding one operation might require overriding another. An overridden operation might be required &lt;br /&gt;
  to call an inherited operation. And subclassing can lead to an explosion of classes, because you might have to introduce&lt;br /&gt;
  many new subclasses for even a simple extension.&lt;br /&gt;
&lt;br /&gt;
Object composition in general and delegation in particular provide flexible alternatives to inheritance for combining behavior.   New functionality can be added to an application by composing existing objects in new ways rather than by defining new subclasses of existing classes. On the other hand, heavy use of object composition can make designs harder to understand. Many design patterns&lt;br /&gt;
produce designs in which you can introduce customized functionality just by defining one subclass and composing its instances with existing ones.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Composite_pattern Composite], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Observer_pattern Observer], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy].&lt;br /&gt;
&lt;br /&gt;
*'''Inability to alter classes conveniently:''' Sometimes you have to modify a class that can't be modified conveniently. Perhaps you need the source code and don't have it (as may be the case with a commercial class library). Or maybe any change would require modifying lots of existing subclasses. Design patterns offer ways to modify classes in such circumstances.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Adapter_pattern Adapter], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
These examples reflect the flexibility that design patterns can help you build into your software. How crucial such flexibility is depends on the kind of software you're building.&lt;br /&gt;
&lt;br /&gt;
'''Advantages:'''&lt;br /&gt;
*Enables large scale reuse of software.&lt;br /&gt;
*Helps in improving developer communication.&lt;br /&gt;
*Captures expert knowledge and design trade-offs and make expertise widely available&lt;br /&gt;
&lt;br /&gt;
'''Disadvantages:'''&lt;br /&gt;
*Does not lead to direct code reuse and is complex in nature.&lt;br /&gt;
*They are validated by experience and discussion.&lt;br /&gt;
*They consume more memory because of generalized format.&lt;br /&gt;
*They are optimized to store any kind of data. This can degrade performance.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;br /&gt;
http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance/&amp;lt;br&amp;gt;&lt;br /&gt;
http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.kuro5hin.org/story/2002/7/14/81923/3656&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.palserv.com/dp/DesignPatternsOverview.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=70921</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=70921"/>
		<updated>2012-11-20T00:10:22Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Program to an interface, not an implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
An example why we have to program to an interface is shown below:&lt;br /&gt;
&amp;lt;pre&amp;gt;   &lt;br /&gt;
public ProcessedBeans processBeans(Beans beans){&lt;br /&gt;
    ProcessedBeans processedBeans = beans.getProcessedBeans();  &lt;br /&gt;
    return processedBeans;  &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above code, we are programming for an implementation assuming that beans is the only item that needs processing. But, as we know, this is not the case. We have to process other food items as well before consumption. Due to the way we have programmed it now we will have to add many more functions for each type of food item that needs processing. This can be avoided, however, by programming to an interface.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public ProcessedFood processFood(FoodItem foodItem){  &lt;br /&gt;
    ProcessedFood processedFood = foodItem.getProcessedItem();  &lt;br /&gt;
    return processedFood;&lt;br /&gt;
}  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By doing so, we have eliminated the need to add new functions for each food type as already noted.&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
Inheritance is good to represent ''is-a'' relationships but is not suitable for portraying ''has-a'' relationships. Many relationships between classes or components do not fall into the ''is-a'' category. (for example, a Car class is likely not a HashMap, but it may have a HashMap). In these scenarios it follows the composition is a better idea for modeling relationships between classes rather than inheritance.&lt;br /&gt;
&lt;br /&gt;
Below is one simple example where composition is much suited than inheritance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Flight extends Journey {...}&lt;br /&gt;
Class Bus extends Journey {...}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, instead of having a sub-class for Flight, class Journey can have a new field which is TransportMode which represents different modes of transport such as flight, bus, train etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class TransportMode {&lt;br /&gt;
  TransportType type;&lt;br /&gt;
  double getCost(double distance) {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  TransportMode mode;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  double getCost() { mode.getCost( getDistance() ) }&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However this is not to say that inheritance should not be used at all. Below is another example which shows that inheritance is the one which we should be using. Here the Human class represents a ''is-a'' relationship with Animal class which is quite natural and the proper way to look at the classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Animal {&lt;br /&gt;
    private String name;&lt;br /&gt;
    public String getName(){&lt;br /&gt;
        return name;&lt;br /&gt;
    }&lt;br /&gt;
    abstract String isIntelligent();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Cat extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;No&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Human extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;Yes&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In short, one should use inheritance for behavioral purposes ie., subclasses should override methods to specialize the behavior of the method and the object itself.&lt;br /&gt;
&lt;br /&gt;
'''Benefits of object composition'''&amp;lt;br&amp;gt;&lt;br /&gt;
* To favour composition over inheritance is a design principle that gives the design higher flexibility.&lt;br /&gt;
* Initial design becomes simple by avoiding hierarchical relationship among classes via inheritance and by identifying object behaviors in separate interfaces. &lt;br /&gt;
* Can easily accommodate future requirements without having to restructure large portions of code.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&amp;lt;br&amp;gt;&lt;br /&gt;
* All of the methods provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods.&lt;br /&gt;
* In inheritance the derived class only need to implement methods whose behavior needs to be modified.. &lt;br /&gt;
* Significantly less programming effort if only a handful of functions in the superclass needs to be overridden in the subclass.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
The key to identifying what should be variable lies in anticipating new requirements and changes to the existing requirements. The system must be designed in such a way so that it can evolve accordingly. Designing a robust system is we must take into account unforeseen changes to avoid a major design overhaul in future. Those changes might involve class redefinition and re-implementation, client modification, and retesting.Redesign affects many parts of the software system, and unanticipated changes are invariably expensive.&lt;br /&gt;
&lt;br /&gt;
Design patterns help you avoid this by ensuring that a system can change in specific ways. Each design pattern lets some aspect of system structure vary independently of other aspects, thereby making a system more robust to a particular kind of change.&lt;br /&gt;
&lt;br /&gt;
Below are some common causes of redesign along with the design pattern(s) that address them:&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Creating an object by specifying a class explicitly:''' Specifying a class name when you create an object commits you to a particular implementation instead of a particular interface. This commitment can complicate future changes. To avoid it, create objects indirectly.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Factory_method_pattern Factory Method], [http://en.wikipedia.org/wiki/Prototype_pattern Prototype].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on specific operations:''' When you specify a particular operation, you commit to one way of satisfying a request. By avoiding hard-coded requests, you make it easier to change the way a request gets satisfied both at compile-time and at run-time.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on hardware and software platform:''' External operating system interfaces and application programming interfaces (APIs) are different on different hardware and software platforms. Software that depends on a particular platform will be harder to port to other platforms. It may even be difficult to keep it up to date on its native platform. It's important therefore to design your system to limit its platform dependencies.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge].&lt;br /&gt;
&lt;br /&gt;
*'''Dependence on object representations or implementation:''' Clients that know how an object is represented, stored, located, or implemented might need to be changed when the object changes. Hiding this information from clients keeps changes from cascading.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Memento_pattern Memento], [http://en.wikipedia.org/wiki/Proxy_pattern Proxy].&lt;br /&gt;
&lt;br /&gt;
*'''Algorithmic dependencies:''' Algorithms are often extended, optimized, and replaced during development and reuse. Objects that depend on an algorithm will have to change when the algorithm changes. Therefore algorithms that are likely to change should be isolated.&lt;br /&gt;
  &lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Builder_pattern Builder], [http://en.wikipedia.org/wiki/Iterator_pattern Iterator], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy], [http://en.wikipedia.org/wiki/Template_method_pattern Template Method], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
*'''Tight coupling:''' Classes that are tightly coupled are hard to reuse in isolation, since they depend on each other. Tight coupling leads to monolithic systems, where you can't change or remove a class without understanding and changing many other classes. The system becomes a dense mass that's hard to learn, port, and maintain.Loose coupling increases the probability that a class can be reused by itself and that a system can be learned, ported, modified, and extended more easily. Design patterns use techniques such as abstract coupling and layering to promote loosely coupled systems.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory], [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Command_pattern Command], [http://en.wikipedia.org/wiki/Facade_pattern Facade], [http://en.wikipedia.org/wiki/Mediator_pattern Mediator], [http://en.wikipedia.org/wiki/Observer_pattern Observer].&lt;br /&gt;
&lt;br /&gt;
*'''Extending functionality by subclassing:''' Customizing an object by subclassing often isn't easy. Every new class has a fixed implementation overhead (initialization, finalization, etc.). Defining a subclass also requires an in-depth understanding of the parent class. For example, &lt;br /&gt;
&lt;br /&gt;
  Overriding one operation might require overriding another. An overridden operation might be required &lt;br /&gt;
  to call an inherited operation. And subclassing can lead to an explosion of classes, because you might have to introduce&lt;br /&gt;
  many new subclasses for even a simple extension.&lt;br /&gt;
&lt;br /&gt;
Object composition in general and delegation in particular provide flexible alternatives to inheritance for combining behavior.   New functionality can be added to an application by composing existing objects in new ways rather than by defining new subclasses of existing classes. On the other hand, heavy use of object composition can make designs harder to understand. Many design patterns&lt;br /&gt;
produce designs in which you can introduce customized functionality just by defining one subclass and composing its instances with existing ones.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Bridge_pattern Bridge], [http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern Chain of Responsibility], [http://en.wikipedia.org/wiki/Composite_pattern Composite], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Observer_pattern Observer], [http://en.wikipedia.org/wiki/Strategy_pattern Strategy].&lt;br /&gt;
&lt;br /&gt;
*'''Inability to alter classes conveniently:''' Sometimes you have to modify a class that can't be modified conveniently. Perhaps you need the source code and don't have it (as may be the case with a commercial class library). Or maybe any change would require modifying lots of existing subclasses. Design patterns offer ways to modify classes in such circumstances.&lt;br /&gt;
&lt;br /&gt;
  '''Design patterns:''' [http://en.wikipedia.org/wiki/Adapter_pattern Adapter], [http://en.wikipedia.org/wiki/Decorator_pattern Decorator], [http://en.wikipedia.org/wiki/Visitor_pattern Visitor].&lt;br /&gt;
&lt;br /&gt;
These examples reflect the flexibility that design patterns can help you build into your software. How crucial such flexibility is depends on the kind of software you're building.&lt;br /&gt;
&lt;br /&gt;
'''Advantages:'''&lt;br /&gt;
*Enables large scale reuse of software.&lt;br /&gt;
*Helps in improving developer communication.&lt;br /&gt;
*Captures expert knowledge and design trade-offs and make expertise widely available&lt;br /&gt;
&lt;br /&gt;
'''Disadvantages:'''&lt;br /&gt;
*Does not lead to direct code reuse and is complex in nature.&lt;br /&gt;
*They are validated by experience and discussion.&lt;br /&gt;
*They consume more memory because of generalized format.&lt;br /&gt;
*They are optimized to store any kind of data. This can degrade performance.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;br /&gt;
http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance/&amp;lt;br&amp;gt;&lt;br /&gt;
http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.kuro5hin.org/story/2002/7/14/81923/3656&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.palserv.com/dp/DesignPatternsOverview.html&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=70297</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=70297"/>
		<updated>2012-11-18T19:35:38Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* REFERENCES */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
Inheritance is good to represent ''is-a'' relationships but is not suitable for portraying ''has-a'' relationships. Many relationships between classes or components do not fall into the ''is-a'' category. (for example, a Car class is likely not a HashMap, but it may have a HashMap). In these scenarios it follows the composition is a better idea for modeling relationships between classes rather than inheritance.&lt;br /&gt;
&lt;br /&gt;
Below is one simple example where composition is much suited than inheritance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Flight extends Journey {...}&lt;br /&gt;
Class Bus extends Journey {...}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, instead of having a sub-class for Flight, class Journey can have a new field which is TransportMode which represents different modes of transport such as flight, bus, train etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class TransportMode {&lt;br /&gt;
  TransportType type;&lt;br /&gt;
  double getCost(double distance) {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  TransportMode mode;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  double getCost() { mode.getCost( getDistance() ) }&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However this is not to say that inheritance should not be used at all. Below is another example which shows that inheritance is the one which we should be using. Here the Human class represents a ''is-a'' relationship with Animal class which is quite natural and the proper way to look at the classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Animal {&lt;br /&gt;
    private String name;&lt;br /&gt;
    public String getName(){&lt;br /&gt;
        return name;&lt;br /&gt;
    }&lt;br /&gt;
    abstract String isIntelligent();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Cat extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;No&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Human extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;Yes&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In short, one should use inheritance for behavioral purposes ie., subclasses should override methods to specialize the behavior of the method and the object itself.&lt;br /&gt;
&lt;br /&gt;
'''Benefits of object composition'''&amp;lt;br&amp;gt;&lt;br /&gt;
* To favour composition over inheritance is a design principle that gives the design higher flexibility.&lt;br /&gt;
* Initial design becomes simple by avoiding hierarchical relationship among classes via inheritance and by identifying object behaviors in separate interfaces. &lt;br /&gt;
* Can easily accommodate future requirements without having to restructure large portions of code.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&amp;lt;br&amp;gt;&lt;br /&gt;
* All of the methods provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods.&lt;br /&gt;
* In inheritance the derived class only need to implement methods whose behavior needs to be modified.. &lt;br /&gt;
* Significantly less programming effort if only a handful of functions in the superclass needs to be overridden in the subclass.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;br /&gt;
http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance/&amp;lt;br&amp;gt;&lt;br /&gt;
http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.kuro5hin.org/story/2002/7/14/81923/3656&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=70289</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=70289"/>
		<updated>2012-11-18T19:29:55Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Favor object composition over class inheritance */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
Inheritance is good to represent ''is-a'' relationships but is not suitable for portraying ''has-a'' relationships. Many relationships between classes or components do not fall into the ''is-a'' category. (for example, a Car class is likely not a HashMap, but it may have a HashMap). In these scenarios it follows the composition is a better idea for modeling relationships between classes rather than inheritance.&lt;br /&gt;
&lt;br /&gt;
Below is one simple example where composition is much suited than inheritance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Flight extends Journey {...}&lt;br /&gt;
Class Bus extends Journey {...}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, instead of having a sub-class for Flight, class Journey can have a new field which is TransportMode which represents different modes of transport such as flight, bus, train etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class TransportMode {&lt;br /&gt;
  TransportType type;&lt;br /&gt;
  double getCost(double distance) {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  TransportMode mode;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  double getCost() { mode.getCost( getDistance() ) }&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However this is not to say that inheritance should not be used at all. Below is another example which shows that inheritance is the one which we should be using. Here the Human class represents a ''is-a'' relationship with Animal class which is quite natural and the proper way to look at the classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Animal {&lt;br /&gt;
    private String name;&lt;br /&gt;
    public String getName(){&lt;br /&gt;
        return name;&lt;br /&gt;
    }&lt;br /&gt;
    abstract String isIntelligent();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Cat extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;No&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Human extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;Yes&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In short, one should use inheritance for behavioral purposes ie., subclasses should override methods to specialize the behavior of the method and the object itself.&lt;br /&gt;
&lt;br /&gt;
'''Benefits of object composition'''&amp;lt;br&amp;gt;&lt;br /&gt;
* To favour composition over inheritance is a design principle that gives the design higher flexibility.&lt;br /&gt;
* Initial design becomes simple by avoiding hierarchical relationship among classes via inheritance and by identifying object behaviors in separate interfaces. &lt;br /&gt;
* Can easily accommodate future requirements without having to restructure large portions of code.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&amp;lt;br&amp;gt;&lt;br /&gt;
* All of the methods provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods.&lt;br /&gt;
* In inheritance the derived class only need to implement methods whose behavior needs to be modified.. &lt;br /&gt;
* Significantly less programming effort if only a handful of functions in the superclass needs to be overridden in the subclass.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;br /&gt;
http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance/&amp;lt;br&amp;gt;&lt;br /&gt;
http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=70284</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=70284"/>
		<updated>2012-11-18T19:20:01Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Favor object composition over class inheritance */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
Inheritance is good to represent ''is-a'' relationships but is not suitable for portraying ''has-a'' relationships. Many relationships between classes or components do not fall into the ''is-a'' category. (for example, a Car class is likely not a HashMap, but it may have a HashMap). In these scenarios it follows the composition is a better idea for modeling relationships between classes rather than inheritance.&lt;br /&gt;
&lt;br /&gt;
Below is one simple example where composition is much suited than inheritance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Flight extends Journey {...}&lt;br /&gt;
Class Bus extends Journey {...}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, instead of having a sub-class for Flight, class Journey can have a new field which is TransportMode which represents different modes of transport such as flight, bus, train etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class TransportMode {&lt;br /&gt;
  TransportType type;&lt;br /&gt;
  double getCost(double distance) {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  TransportMode mode;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  double getCost() { mode.getCost( getDistance() ) }&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However this is not to say that inheritance should not be used at all. Below is another example which shows that inheritance is the one which we should be using. Here the Human class represents a ''is-a'' relationship with Animal class which is quite natural and the proper way to look at the classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Animal {&lt;br /&gt;
    private String name;&lt;br /&gt;
    public String getName(){&lt;br /&gt;
        return name;&lt;br /&gt;
    }&lt;br /&gt;
    abstract String isIntelligent();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Cat extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;No&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Human extends Animal{&lt;br /&gt;
    public String isIntelligent(){&lt;br /&gt;
        return &amp;quot;Yes&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In short, one should use inheritance for behavioral purposes ie., subclasses should override methods to specialize the behavior of the method and the object itself.&lt;br /&gt;
&lt;br /&gt;
'''Benefits of object composition'''&amp;lt;br&amp;gt;&lt;br /&gt;
To favour composition over inheritance is a design principle that gives the design higher flexibility, giving business-domain classes and more stable business domain in the long term. In other words, HAS-A can be better than an IS-A relationship.&lt;br /&gt;
Initial design is simplified by identifying system object behaviors in separate interfaces instead of creating a hierarchical relationship to distribute behaviors among business-domain classes via inheritance. This approach more easily accommodates future requirements changes that would otherwise require a complete restructuring of business-domain classes in the inheritance model. Additionally, it avoids problems often associated with relatively minor changes to an inheritance-based model that includes several generations of classes.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&amp;lt;br&amp;gt;&lt;br /&gt;
One drawback to using composition in place of inheritance is that all of the methods being provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods. In contrast, inheritance does not require all of a base class's methods to be re-implemented within the derived class. Rather, the derived class need only implement (override) the methods having different behavior than the base class methods. This can require significantly less programming effort if the base class contains many methods providing default behavior and only a few of them need to be overridden within the derived class.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;br /&gt;
http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance/&amp;lt;br&amp;gt;&lt;br /&gt;
http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=70276</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=70276"/>
		<updated>2012-11-18T19:15:37Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Favor object composition over class inheritance */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
Inheritance is good to represent ''is-a'' relationships but is not suitable for portraying ''has-a'' relationships. Many relationships between classes or components do not fall into the ''is-a'' category. (for example, a Car class is likely not a HashMap, but it may have a HashMap). In these scenarios it follows the composition is a better idea for modeling relationships between classes rather than inheritance.&lt;br /&gt;
&lt;br /&gt;
Below is one simple example where composition is much suited than inheritance.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Flight extends Journey {...}&lt;br /&gt;
Class Bus extends Journey {...}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, instead of having a sub-class for Flight, class Journey can have a new field which is TransportMode which represents different modes of transport such as flight, bus, train etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class TransportMode {&lt;br /&gt;
  TransportType type;&lt;br /&gt;
  double getCost(double distance) {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  TransportMode mode;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  double getCost() { mode.getCost( getDistance() ) }&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However this is not to say that inheritance should not be used at all. Below is another example which shows that inheritance is the one which we should be using.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
abstract class Animal {&lt;br /&gt;
    private String name;&lt;br /&gt;
    public String getName(){&lt;br /&gt;
        return name;&lt;br /&gt;
    }&lt;br /&gt;
    abstract int getLegCount();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Dog extends Animal{&lt;br /&gt;
    public int getLegCount(){&lt;br /&gt;
        return 4;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Human extends Animal{&lt;br /&gt;
    public int getLegCount(){&lt;br /&gt;
        return 2;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In short, one should use inheritance for behavioral purposes ie., subclasses should override methods to specialize the behavior of the method and the object itself.&lt;br /&gt;
&lt;br /&gt;
'''Benefits of object composition'''&amp;lt;br&amp;gt;&lt;br /&gt;
To favour composition over inheritance is a design principle that gives the design higher flexibility, giving business-domain classes and more stable business domain in the long term. In other words, HAS-A can be better than an IS-A relationship.&lt;br /&gt;
Initial design is simplified by identifying system object behaviors in separate interfaces instead of creating a hierarchical relationship to distribute behaviors among business-domain classes via inheritance. This approach more easily accommodates future requirements changes that would otherwise require a complete restructuring of business-domain classes in the inheritance model. Additionally, it avoids problems often associated with relatively minor changes to an inheritance-based model that includes several generations of classes.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&amp;lt;br&amp;gt;&lt;br /&gt;
One drawback to using composition in place of inheritance is that all of the methods being provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods. In contrast, inheritance does not require all of a base class's methods to be re-implemented within the derived class. Rather, the derived class need only implement (override) the methods having different behavior than the base class methods. This can require significantly less programming effort if the base class contains many methods providing default behavior and only a few of them need to be overridden within the derived class.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;br /&gt;
http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance/&amp;lt;br&amp;gt;&lt;br /&gt;
http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=70269</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=70269"/>
		<updated>2012-11-18T19:08:27Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Favor object composition over class inheritance */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
Inheritance is good to represent ''is-a'' relationships but is not suitable for portraying ''has-a'' relationships. Many relationships between classes or components do not fall into the ''is-a'' category. (for example, a Car class is likely not a HashMap, but it may have a HashMap). In these scenarios it follows the composition is a better idea for modeling relationships between classes rather than inheritance.&lt;br /&gt;
&lt;br /&gt;
This is not to say however that inheritance is not useful or not the correct solution at all.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Flight extends Journey {...}&lt;br /&gt;
Class Bus extends Journey {...}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, instead of having a sub-class for Flight, class Journey can have a new field which is TransportMode which represents different modes of transport such as flight, bus, train etc.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class TransportMode {&lt;br /&gt;
  TransportType type;&lt;br /&gt;
  double getCost(double distance) {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  TransportMode mode;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  double getCost() { mode.getCost( getDistance() ) }&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Benefits'''&amp;lt;br&amp;gt;&lt;br /&gt;
To favour composition over inheritance is a design principle that gives the design higher flexibility, giving business-domain classes and more stable business domain in the long term. In other words, HAS-A can be better than an IS-A relationship.&lt;br /&gt;
Initial design is simplified by identifying system object behaviors in separate interfaces instead of creating a hierarchical relationship to distribute behaviors among business-domain classes via inheritance. This approach more easily accommodates future requirements changes that would otherwise require a complete restructuring of business-domain classes in the inheritance model. Additionally, it avoids problems often associated with relatively minor changes to an inheritance-based model that includes several generations of classes.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&amp;lt;br&amp;gt;&lt;br /&gt;
One drawback to using composition in place of inheritance is that all of the methods being provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods. In contrast, inheritance does not require all of a base class's methods to be re-implemented within the derived class. Rather, the derived class need only implement (override) the methods having different behavior than the base class methods. This can require significantly less programming effort if the base class contains many methods providing default behavior and only a few of them need to be overridden within the derived class.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;br /&gt;
http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance/&amp;lt;br&amp;gt;&lt;br /&gt;
http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=70264</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=70264"/>
		<updated>2012-11-18T19:02:31Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* REFERENCES */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Flight extends Journey {...}&lt;br /&gt;
Class Bus extends Journey {...}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, instead of having a sub-class for Flight, class Journey can have a new field which is TransportMode which represents different modes of transport such as flight, bus, train etc.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class TransportMode {&lt;br /&gt;
  TransportType type;&lt;br /&gt;
  double getCost(double distance) {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  TransportMode mode;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  double getCost() { mode.getCost( getDistance() ) }&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Benefits'''&amp;lt;br&amp;gt;&lt;br /&gt;
To favour composition over inheritance is a design principle that gives the design higher flexibility, giving business-domain classes and more stable business domain in the long term. In other words, HAS-A can be better than an IS-A relationship.&lt;br /&gt;
Initial design is simplified by identifying system object behaviors in separate interfaces instead of creating a hierarchical relationship to distribute behaviors among business-domain classes via inheritance. This approach more easily accommodates future requirements changes that would otherwise require a complete restructuring of business-domain classes in the inheritance model. Additionally, it avoids problems often associated with relatively minor changes to an inheritance-based model that includes several generations of classes.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&amp;lt;br&amp;gt;&lt;br /&gt;
One drawback to using composition in place of inheritance is that all of the methods being provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods. In contrast, inheritance does not require all of a base class's methods to be re-implemented within the derived class. Rather, the derived class need only implement (override) the methods having different behavior than the base class methods. This can require significantly less programming effort if the base class contains many methods providing default behavior and only a few of them need to be overridden within the derived class.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;br /&gt;
http://stackoverflow.com/questions/3979581/disadvantage-of-object-composition-over-class-inheritance&amp;lt;br&amp;gt;&lt;br /&gt;
http://blog.fedecarg.com/2008/09/04/favour-object-composition-over-class-inheritance/&amp;lt;br&amp;gt;&lt;br /&gt;
http://programmers.stackexchange.com/questions/65179/where-does-this-concept-of-favor-composition-over-inheritance-come-from&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=70262</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=70262"/>
		<updated>2012-11-18T19:00:23Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Favor object composition over class inheritance */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&amp;lt;br&amp;gt;&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Flight extends Journey {...}&lt;br /&gt;
Class Bus extends Journey {...}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, instead of having a sub-class for Flight, class Journey can have a new field which is TransportMode which represents different modes of transport such as flight, bus, train etc.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class Location {&lt;br /&gt;
  String name;&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class TransportMode {&lt;br /&gt;
  TransportType type;&lt;br /&gt;
  double getCost(double distance) {...}&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Class Journey {&lt;br /&gt;
  Location source, destination;&lt;br /&gt;
  TransportMode mode;&lt;br /&gt;
  double getDistance() {...}&lt;br /&gt;
  double getCost() { mode.getCost( getDistance() ) }&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Benefits'''&amp;lt;br&amp;gt;&lt;br /&gt;
To favour composition over inheritance is a design principle that gives the design higher flexibility, giving business-domain classes and more stable business domain in the long term. In other words, HAS-A can be better than an IS-A relationship.&lt;br /&gt;
Initial design is simplified by identifying system object behaviors in separate interfaces instead of creating a hierarchical relationship to distribute behaviors among business-domain classes via inheritance. This approach more easily accommodates future requirements changes that would otherwise require a complete restructuring of business-domain classes in the inheritance model. Additionally, it avoids problems often associated with relatively minor changes to an inheritance-based model that includes several generations of classes.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&amp;lt;br&amp;gt;&lt;br /&gt;
One drawback to using composition in place of inheritance is that all of the methods being provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods. In contrast, inheritance does not require all of a base class's methods to be re-implemented within the derived class. Rather, the derived class need only implement (override) the methods having different behavior than the base class methods. This can require significantly less programming effort if the base class contains many methods providing default behavior and only a few of them need to be overridden within the derived class.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=70120</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=70120"/>
		<updated>2012-11-18T08:24:17Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Program to an interface, not an implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object is able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies. So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&lt;br /&gt;
&lt;br /&gt;
The first principle of design patterns is also tied to polymorphism as noted above. Let us look at this part in more detail.&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Another way to look at this principle is that one should focus not only on developing one single version of an application, but to design it keeping in mind that one have to maintain and keep the API stable for a sustained period of time.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
'''Benefits'''&lt;br /&gt;
To favour composition over inheritance is a design principle that gives the design higher flexibility, giving business-domain classes and more stable business domain in the long term. In other words, HAS-A can be better than an IS-A relationship.&lt;br /&gt;
Initial design is simplified by identifying system object behaviors in separate interfaces instead of creating a hierarchical relationship to distribute behaviors among business-domain classes via inheritance. This approach more easily accommodates future requirements changes that would otherwise require a complete restructuring of business-domain classes in the inheritance model. Additionally, it avoids problems often associated with relatively minor changes to an inheritance-based model that includes several generations of classes.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&lt;br /&gt;
One drawback to using composition in place of inheritance is that all of the methods being provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods. In contrast, inheritance does not require all of a base class's methods to be re-implemented within the derived class. Rather, the derived class need only implement (override) the methods having different behavior than the base class methods. This can require significantly less programming effort if the base class contains many methods providing default behavior and only a few of them need to be overridden within the derived class.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69968</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69968"/>
		<updated>2012-11-17T19:54:16Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Favor object composition over class inheritance */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object(s)is(are) able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
For example: &lt;br /&gt;
&lt;br /&gt;
So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&lt;br /&gt;
&lt;br /&gt;
Polymorphism has been discussed elsewhere on this blog, and we all know it is one of the pillars of OOP. This first principle of design patterns is tied into polymorphism. In order to follow the path from interfaces to polymorphism, we need to start with an operation’s signature. As you know, a signature is made up of the following:&lt;br /&gt;
&lt;br /&gt;
operation’s name&lt;br /&gt;
objects it takes as parameters&lt;br /&gt;
return value&lt;br /&gt;
In this context we can discuss interfaces as all of the operations in an object. For the most part, an object as used by GoF refers to a class and not an instance of a class as the term object is conventionally used. (I won’t belabor the meaning of signatures and interfaces here, but if you want more details on both concepts, see the discussion beginning on page 19 of our book.)&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Design patterns help you set up interfaces and use polymorphism in organizing your program. The more you look at the different principles of OOP, the more you can see how these principles are maintained and presented in design patterns. Key are ActionScript 3.0 pure interfaces and abstract classes. All operations in an interface are abstract, but an abstract class can defer some or all implementations to derived classes (subclasses.) Thus, the abstract class is more flexible than the pure interface, but both serve as interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that you should focus not only on developing version one, but to also think about the next versions. This doesn't mean designing in future extensibility, but just keeping in mind that you have to maintain what you produce and try to keep the API stable for a long time. You want to build to last.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Why do we need this?'''&lt;br /&gt;
Both methods - object composition and inheritance provide a means for code reuse which is one of the fundamental principles of OO programming. With inheritance the subclasses are tightly coupled to the parent classes which reduces the flexibility. Each subclass knows the internal representation of the parent class which break encapsulation. This creates a dependency between the subclass and the superclass which is not a desirable trait. This is why inheritance is generally referred to as '''''white box''''' reuse. In most scenarios you do not want to expose the internal implementation of the super class and that is where composition comes into play.&lt;br /&gt;
&lt;br /&gt;
'''Benefits'''&lt;br /&gt;
To favour composition over inheritance is a design principle that gives the design higher flexibility, giving business-domain classes and more stable business domain in the long term. In other words, HAS-A can be better than an IS-A relationship.&lt;br /&gt;
Initial design is simplified by identifying system object behaviors in separate interfaces instead of creating a hierarchical relationship to distribute behaviors among business-domain classes via inheritance. This approach more easily accommodates future requirements changes that would otherwise require a complete restructuring of business-domain classes in the inheritance model. Additionally, it avoids problems often associated with relatively minor changes to an inheritance-based model that includes several generations of classes.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&lt;br /&gt;
One drawback to using composition in place of inheritance is that all of the methods being provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods. In contrast, inheritance does not require all of a base class's methods to be re-implemented within the derived class. Rather, the derived class need only implement (override) the methods having different behavior than the base class methods. This can require significantly less programming effort if the base class contains many methods providing default behavior and only a few of them need to be overridden within the derived class.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69967</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69967"/>
		<updated>2012-11-17T19:42:28Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Favor object composition over class inheritance */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object(s)is(are) able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
For example: &lt;br /&gt;
&lt;br /&gt;
So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&lt;br /&gt;
&lt;br /&gt;
Polymorphism has been discussed elsewhere on this blog, and we all know it is one of the pillars of OOP. This first principle of design patterns is tied into polymorphism. In order to follow the path from interfaces to polymorphism, we need to start with an operation’s signature. As you know, a signature is made up of the following:&lt;br /&gt;
&lt;br /&gt;
operation’s name&lt;br /&gt;
objects it takes as parameters&lt;br /&gt;
return value&lt;br /&gt;
In this context we can discuss interfaces as all of the operations in an object. For the most part, an object as used by GoF refers to a class and not an instance of a class as the term object is conventionally used. (I won’t belabor the meaning of signatures and interfaces here, but if you want more details on both concepts, see the discussion beginning on page 19 of our book.)&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Design patterns help you set up interfaces and use polymorphism in organizing your program. The more you look at the different principles of OOP, the more you can see how these principles are maintained and presented in design patterns. Key are ActionScript 3.0 pure interfaces and abstract classes. All operations in an interface are abstract, but an abstract class can defer some or all implementations to derived classes (subclasses.) Thus, the abstract class is more flexible than the pure interface, but both serve as interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that you should focus not only on developing version one, but to also think about the next versions. This doesn't mean designing in future extensibility, but just keeping in mind that you have to maintain what you produce and try to keep the API stable for a long time. You want to build to last.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Benefits'''&lt;br /&gt;
To favour composition over inheritance is a design principle that gives the design higher flexibility, giving business-domain classes and more stable business domain in the long term. In other words, HAS-A can be better than an IS-A relationship.[1]&lt;br /&gt;
Initial design is simplified by identifying system object behaviors in separate interfaces instead of creating a hierarchical relationship to distribute behaviors among business-domain classes via inheritance. This approach more easily accommodates future requirements changes that would otherwise require a complete restructuring of business-domain classes in the inheritance model. Additionally, it avoids problems often associated with relatively minor changes to an inheritance-based model that includes several generations of classes.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&lt;br /&gt;
One drawback to using composition in place of inheritance is that all of the methods being provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods. In contrast, inheritance does not require all of a base class's methods to be re-implemented within the derived class. Rather, the derived class need only implement (override) the methods having different behavior than the base class methods. This can require significantly less programming effort if the base class contains many methods providing default behavior and only a few of them need to be overridden within the derived class.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69966</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69966"/>
		<updated>2012-11-17T19:42:14Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Favor object composition over class inheritance */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object(s)is(are) able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
For example: &lt;br /&gt;
&lt;br /&gt;
So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&lt;br /&gt;
&lt;br /&gt;
Polymorphism has been discussed elsewhere on this blog, and we all know it is one of the pillars of OOP. This first principle of design patterns is tied into polymorphism. In order to follow the path from interfaces to polymorphism, we need to start with an operation’s signature. As you know, a signature is made up of the following:&lt;br /&gt;
&lt;br /&gt;
operation’s name&lt;br /&gt;
objects it takes as parameters&lt;br /&gt;
return value&lt;br /&gt;
In this context we can discuss interfaces as all of the operations in an object. For the most part, an object as used by GoF refers to a class and not an instance of a class as the term object is conventionally used. (I won’t belabor the meaning of signatures and interfaces here, but if you want more details on both concepts, see the discussion beginning on page 19 of our book.)&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Design patterns help you set up interfaces and use polymorphism in organizing your program. The more you look at the different principles of OOP, the more you can see how these principles are maintained and presented in design patterns. Key are ActionScript 3.0 pure interfaces and abstract classes. All operations in an interface are abstract, but an abstract class can defer some or all implementations to derived classes (subclasses.) Thus, the abstract class is more flexible than the pure interface, but both serve as interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that you should focus not only on developing version one, but to also think about the next versions. This doesn't mean designing in future extensibility, but just keeping in mind that you have to maintain what you produce and try to keep the API stable for a long time. You want to build to last.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
'''Definitions''': &lt;br /&gt;
* ''[http://en.wikipedia.org/wiki/Object_composition Object Composition]'' is a way to combine simple objects or data types into more complex ones.&lt;br /&gt;
* Composition over inheritance (or Composite Reuse Principle) in object-oriented programming is a technique by which classes may achieve polymorphic behavior and code reuse by containing other classes that implement the desired functionality instead of through inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Benefits''&lt;br /&gt;
To favour composition over inheritance is a design principle that gives the design higher flexibility, giving business-domain classes and more stable business domain in the long term. In other words, HAS-A can be better than an IS-A relationship.[1]&lt;br /&gt;
Initial design is simplified by identifying system object behaviors in separate interfaces instead of creating a hierarchical relationship to distribute behaviors among business-domain classes via inheritance. This approach more easily accommodates future requirements changes that would otherwise require a complete restructuring of business-domain classes in the inheritance model. Additionally, it avoids problems often associated with relatively minor changes to an inheritance-based model that includes several generations of classes.&lt;br /&gt;
&lt;br /&gt;
'''Drawbacks'''&lt;br /&gt;
One drawback to using composition in place of inheritance is that all of the methods being provided by the composed classes must be implemented in the derived class, even if they are only forwarding methods. In contrast, inheritance does not require all of a base class's methods to be re-implemented within the derived class. Rather, the derived class need only implement (override) the methods having different behavior than the base class methods. This can require significantly less programming effort if the base class contains many methods providing default behavior and only a few of them need to be overridden within the derived class.&lt;br /&gt;
&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69962</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69962"/>
		<updated>2012-11-17T19:11:46Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object(s)is(are) able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
For example: &lt;br /&gt;
&lt;br /&gt;
So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&lt;br /&gt;
&lt;br /&gt;
Polymorphism has been discussed elsewhere on this blog, and we all know it is one of the pillars of OOP. This first principle of design patterns is tied into polymorphism. In order to follow the path from interfaces to polymorphism, we need to start with an operation’s signature. As you know, a signature is made up of the following:&lt;br /&gt;
&lt;br /&gt;
operation’s name&lt;br /&gt;
objects it takes as parameters&lt;br /&gt;
return value&lt;br /&gt;
In this context we can discuss interfaces as all of the operations in an object. For the most part, an object as used by GoF refers to a class and not an instance of a class as the term object is conventionally used. (I won’t belabor the meaning of signatures and interfaces here, but if you want more details on both concepts, see the discussion beginning on page 19 of our book.)&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Design patterns help you set up interfaces and use polymorphism in organizing your program. The more you look at the different principles of OOP, the more you can see how these principles are maintained and presented in design patterns. Key are ActionScript 3.0 pure interfaces and abstract classes. All operations in an interface are abstract, but an abstract class can defer some or all implementations to derived classes (subclasses.) Thus, the abstract class is more flexible than the pure interface, but both serve as interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that you should focus not only on developing version one, but to also think about the next versions. This doesn't mean designing in future extensibility, but just keeping in mind that you have to maintain what you produce and try to keep the API stable for a long time. You want to build to last.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.as3dp.com/2009/02/design-pattern-principles-for-actionscript-30-program-to-an-interface-not-an-implementation/&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69959</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69959"/>
		<updated>2012-11-17T18:31:16Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Program to an interface, not an implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word ''interface'' is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object(s)is(are) able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
For example: &lt;br /&gt;
&lt;br /&gt;
So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
'''Dynamic Binding, Polymorphism and Interfaces'''&lt;br /&gt;
&lt;br /&gt;
Polymorphism has been discussed elsewhere on this blog, and we all know it is one of the pillars of OOP. This first principle of design patterns is tied into polymorphism. In order to follow the path from interfaces to polymorphism, we need to start with an operation’s signature. As you know, a signature is made up of the following:&lt;br /&gt;
&lt;br /&gt;
operation’s name&lt;br /&gt;
objects it takes as parameters&lt;br /&gt;
return value&lt;br /&gt;
In this context we can discuss interfaces as all of the operations in an object. For the most part, an object as used by GoF refers to a class and not an instance of a class as the term object is conventionally used. (I won’t belabor the meaning of signatures and interfaces here, but if you want more details on both concepts, see the discussion beginning on page 19 of our book.)&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Design patterns help you set up interfaces and use polymorphism in organizing your program. The more you look at the different principles of OOP, the more you can see how these principles are maintained and presented in design patterns. Key are ActionScript 3.0 pure interfaces and abstract classes. All operations in an interface are abstract, but an abstract class can defer some or all implementations to derived classes (subclasses.) Thus, the abstract class is more flexible than the pure interface, but both serve as interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that you should focus not only on developing version one, but to also think about the next versions. This doesn't mean designing in future extensibility, but just keeping in mind that you have to maintain what you produce and try to keep the API stable for a long time. You want to build to last.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69958</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69958"/>
		<updated>2012-11-17T18:30:16Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Program to an interface, not an implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word interface is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object(s)is(are) able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
For example: &lt;br /&gt;
&lt;br /&gt;
So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
****Dynamic Binding, Polymorphism and Interfaces****&lt;br /&gt;
&lt;br /&gt;
Polymorphism has been discussed elsewhere on this blog, and we all know it is one of the pillars of OOP. This first principle of design patterns is tied into polymorphism. In order to follow the path from interfaces to polymorphism, we need to start with an operation’s signature. As you know, a signature is made up of the following:&lt;br /&gt;
&lt;br /&gt;
operation’s name&lt;br /&gt;
objects it takes as parameters&lt;br /&gt;
return value&lt;br /&gt;
In this context we can discuss interfaces as all of the operations in an object. For the most part, an object as used by GoF refers to a class and not an instance of a class as the term object is conventionally used. (I won’t belabor the meaning of signatures and interfaces here, but if you want more details on both concepts, see the discussion beginning on page 19 of our book.)&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Design patterns help you set up interfaces and use polymorphism in organizing your program. The more you look at the different principles of OOP, the more you can see how these principles are maintained and presented in design patterns. Key are ActionScript 3.0 pure interfaces and abstract classes. All operations in an interface are abstract, but an abstract class can defer some or all implementations to derived classes (subclasses.) Thus, the abstract class is more flexible than the pure interface, but both serve as interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that you should focus not only on developing version one, but to also think about the next versions. This doesn't mean designing in future extensibility, but just keeping in mind that you have to maintain what you produce and try to keep the API stable for a long time. You want to build to last.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69957</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69957"/>
		<updated>2012-11-17T18:29:12Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Program to an interface, not an implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word interface is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object(s)is(are) able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
For example: &lt;br /&gt;
&lt;br /&gt;
So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
Dynamic Binding, Polymorphism and Interfaces&lt;br /&gt;
&lt;br /&gt;
Polymorphism has been discussed elsewhere on this blog, and we all know it is one of the pillars of OOP. This first principle of design patterns is tied into polymorphism. In order to follow the path from interfaces to polymorphism, we need to start with an operation’s signature. As you know, a signature is made up of the following:&lt;br /&gt;
&lt;br /&gt;
operation’s name&lt;br /&gt;
objects it takes as parameters&lt;br /&gt;
return value&lt;br /&gt;
In this context we can discuss interfaces as all of the operations in an object. For the most part, an object as used by GoF refers to a class and not an instance of a class as the term object is conventionally used. (I won’t belabor the meaning of signatures and interfaces here, but if you want more details on both concepts, see the discussion beginning on page 19 of our book.)&lt;br /&gt;
&lt;br /&gt;
When we type an object, such as,&lt;br /&gt;
&lt;br /&gt;
var myInstance:String;&lt;br /&gt;
&lt;br /&gt;
we tend to think of String as a class type, but in fact it denotes a particular interface. “Any request that matches a signature in the object’s interface may be sent to the object” (GoF 13).&lt;br /&gt;
&lt;br /&gt;
Bumping this up to user created classes, we type to the interface, which is found in the supertype relative to a subtype. That is, a subclasses’ type resides in the parent class. Because all knowledge of an object is known only through its interface, the request does not address the implementation. As a result, objects with different implementations can have the same interface.&lt;br /&gt;
&lt;br /&gt;
Several different objects can have the same interface (primarily based on the superclass) but different implementations, and since the actual operation that is performed is dependent on both the request and receiving object’s name, the actual outcome occurs at run-time. Such an association between the a request and its operation at run-time is known as dynamic binding. The process of dynamic binding lets you substitute objects with identical interfaces at run-time. You probably know this process by another name, polymorphism.&lt;br /&gt;
&lt;br /&gt;
Design patterns help you set up interfaces and use polymorphism in organizing your program. The more you look at the different principles of OOP, the more you can see how these principles are maintained and presented in design patterns. Key are ActionScript 3.0 pure interfaces and abstract classes. All operations in an interface are abstract, but an abstract class can defer some or all implementations to derived classes (subclasses.) Thus, the abstract class is more flexible than the pure interface, but both serve as interfaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that you should focus not only on developing version one, but to also think about the next versions. This doesn't mean designing in future extensibility, but just keeping in mind that you have to maintain what you produce and try to keep the API stable for a long time. You want to build to last.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface. And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69920</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69920"/>
		<updated>2012-11-17T17:19:02Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Program to an interface, not an implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word interface is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface relates to the OO principle of capabilities that the object(s)is(are) able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically ie., to reduce the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
For example: &lt;br /&gt;
&lt;br /&gt;
So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
Another lesson learned is that you should focus not only on developing version one, but to also think about the following versions. This doesn't mean designing in future extensibility, but just keeping in mind that you have to maintain what you produce and try to keep the API stable for a long time. You want to build to last.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface.&lt;br /&gt;
&lt;br /&gt;
And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69919</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69919"/>
		<updated>2012-11-17T17:17:38Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Program to an interface, not an implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word interface is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has a keyword by the same name. Interface in this context is relates to the OO principle of capabilities that the object(s)is(are) able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically.&lt;br /&gt;
&lt;br /&gt;
For example: &lt;br /&gt;
&lt;br /&gt;
So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
Another lesson learned is that you should focus not only on developing version one, but to also think about the following versions. This doesn't mean designing in future extensibility, but just keeping in mind that you have to maintain what you produce and try to keep the API stable for a long time. You want to build to last.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface.&lt;br /&gt;
&lt;br /&gt;
And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69918</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69918"/>
		<updated>2012-11-17T17:15:39Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Program to an interface, not an implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word interface is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has keyword by the same name. Interface in this context is relates to the OO principle of capabilities that the object(s)is(are) able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically.&lt;br /&gt;
&lt;br /&gt;
For example: &lt;br /&gt;
&lt;br /&gt;
So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
Another lesson learned is that you should focus not only on developing version one, but to also think about the following versions. This doesn't mean designing in future extensibility, but just keeping in mind that you have to maintain what you produce and try to keep the API stable for a long time. You want to build to last.&lt;br /&gt;
&lt;br /&gt;
Just by following this rule, you get two very important benefits as stated in the GOF book:&lt;br /&gt;
# Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that the clients expect.&lt;br /&gt;
# Clients remain unaware of the classes that implement these objects. Clients only know about the base/abstract classes or interfaces (C# interface) defining the interface.&lt;br /&gt;
&lt;br /&gt;
And this greatly reduces the implementation dependencies.&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69914</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69914"/>
		<updated>2012-11-17T17:12:25Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this principle, the word interface is more conceptual and should not be seen from the viewpoint of a language like Java or C# which has keyword by the same name. Interface in this context is relates to the OO principle of capabilities that the object(s)is(are) able to support. So by this definition an object can have many types or interfaces, and objects of different classes can have the same interface or type. In this context, the main idea behind this principle is how to decouple the implementation from the interface so that the code can be extended polymorphically.&lt;br /&gt;
&lt;br /&gt;
For example: &lt;br /&gt;
&lt;br /&gt;
So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. &lt;br /&gt;
&lt;br /&gt;
Another lesson learned is that you should focus not only on developing version one, but to also think about the following versions. This doesn't mean designing in future extensibility, but just keeping in mind that you have to maintain what you produce and try to keep the API stable for a long time. You want to build to last. That's been an important theme of Eclipse development since we started. We have built Eclipse as a platform. We always keep in mind as we design Eclipse that it has to last ten or twenty years. This can be scary at times.&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69889</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69889"/>
		<updated>2012-11-17T16:18:09Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The main idea behind this principle is to avoid dependencies as much as possible between different classes by decoupling the interface from the implementation. While it is easy to create dependencies, getting rid of them later during re-factoring is a tough task.  When you have a tight coupling between the implementation and the interface, in the worst case it stops you from reusing the code in another context. For this reason you have to develop with open eyes when it comes to introducing dependencies.&lt;br /&gt;
&lt;br /&gt;
For example: &lt;br /&gt;
&lt;br /&gt;
So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. One question is whether you should always use a Java interfaces for that. An abstract class is good as well. In fact, an abstract class gives you more flexibility when it comes to evolution. You can add new behavior without breaking clients.&lt;br /&gt;
&lt;br /&gt;
In Java when you add a new method to an interface, you break all your clients. When you have an abstract class, you can add a new method and provide a default implementation in it. All the clients will continue to work. As always there is a trade-off, an interface gives you freedom with regard to the base class, an abstract class gives you the freedom to add new methods later. It isn't always possible to define an interface in an abstract class, but in the light of evolution you should consider whether an abstract class is sufficient.&lt;br /&gt;
&lt;br /&gt;
Since changing interfaces breaks clients you should consider them as immutable once you've published them. As a consequence when adding a new method to an interface you have to do so in a separate interface. In Eclipse we take API stability seriously and for this reason you will find so called I*2 interfaces like IMarkerResolution2 or IWorkbenchPart2 in our APIs. These interfaces add methods to the base interfaces IMarkerResolution and IWorkbenchPart. Since the additions are done in separate extension interfaces you do not break the clients. However, there is now some burden on the caller in that they need to determine at run- time whether an object implements a particular extension interface.&lt;br /&gt;
&lt;br /&gt;
Another lesson learned is that you should focus not only on developing version one, but to also think about the following versions. This doesn't mean designing in future extensibility, but just keeping in mind that you have to maintain what you produce and try to keep the API stable for a long time. You want to build to last. That's been an important theme of Eclipse development since we started. We have built Eclipse as a platform. We always keep in mind as we design Eclipse that it has to last ten or twenty years. This can be scary at times.&lt;br /&gt;
&lt;br /&gt;
We added support for evolution in the base platform when we started. One example of this is the IAdaptable interface. Classes implementing this interface can be adapted to another interface. This is an example of the Extension Object pattern,. [4]&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://blogs.msdn.com/b/sachin/archive/2008/06/12/program-to-an-interface-not-an-implementation.aspx&amp;lt;br&amp;gt;&lt;br /&gt;
http://pragmaticjava.blogspot.com/2008/08/program-to-interface-not-implementation.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69888</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69888"/>
		<updated>2012-11-17T16:17:46Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Program to an interface, not an implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The main idea behind this principle is to avoid dependencies as much as possible between different classes by decoupling the interface from the implementation. While it is easy to create dependencies, getting rid of them later during re-factoring is a tough task.  When you have a tight coupling between the implementation and the interface, in the worst case it stops you from reusing the code in another context. For this reason you have to develop with open eyes when it comes to introducing dependencies.&lt;br /&gt;
&lt;br /&gt;
For example: &lt;br /&gt;
&lt;br /&gt;
So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. One question is whether you should always use a Java interfaces for that. An abstract class is good as well. In fact, an abstract class gives you more flexibility when it comes to evolution. You can add new behavior without breaking clients.&lt;br /&gt;
&lt;br /&gt;
In Java when you add a new method to an interface, you break all your clients. When you have an abstract class, you can add a new method and provide a default implementation in it. All the clients will continue to work. As always there is a trade-off, an interface gives you freedom with regard to the base class, an abstract class gives you the freedom to add new methods later. It isn't always possible to define an interface in an abstract class, but in the light of evolution you should consider whether an abstract class is sufficient.&lt;br /&gt;
&lt;br /&gt;
Since changing interfaces breaks clients you should consider them as immutable once you've published them. As a consequence when adding a new method to an interface you have to do so in a separate interface. In Eclipse we take API stability seriously and for this reason you will find so called I*2 interfaces like IMarkerResolution2 or IWorkbenchPart2 in our APIs. These interfaces add methods to the base interfaces IMarkerResolution and IWorkbenchPart. Since the additions are done in separate extension interfaces you do not break the clients. However, there is now some burden on the caller in that they need to determine at run- time whether an object implements a particular extension interface.&lt;br /&gt;
&lt;br /&gt;
Another lesson learned is that you should focus not only on developing version one, but to also think about the following versions. This doesn't mean designing in future extensibility, but just keeping in mind that you have to maintain what you produce and try to keep the API stable for a long time. You want to build to last. That's been an important theme of Eclipse development since we started. We have built Eclipse as a platform. We always keep in mind as we design Eclipse that it has to last ten or twenty years. This can be scary at times.&lt;br /&gt;
&lt;br /&gt;
We added support for evolution in the base platform when we started. One example of this is the IAdaptable interface. Classes implementing this interface can be adapted to another interface. This is an example of the Extension Object pattern,. [4]&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69887</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69887"/>
		<updated>2012-11-17T16:15:09Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Program to an interface, not an implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app - Erich Gamma &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The main idea behind this principle is to avoid dependencies as much as possible between different classes by decoupling the interface from the implementation. While it is easy to create dependencies, getting rid of them later during re-factoring is a tough task.  When you have a tight coupling between the implementation and the interface, in the worst case it stops you from reusing the code in another context. For this reason you have to develop with open eyes when it comes to introducing dependencies.&lt;br /&gt;
&lt;br /&gt;
So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. One question is whether you should always use a Java interfaces for that. An abstract class is good as well. In fact, an abstract class gives you more flexibility when it comes to evolution. You can add new behavior without breaking clients.&lt;br /&gt;
&lt;br /&gt;
In Java when you add a new method to an interface, you break all your clients. When you have an abstract class, you can add a new method and provide a default implementation in it. All the clients will continue to work. As always there is a trade-off, an interface gives you freedom with regard to the base class, an abstract class gives you the freedom to add new methods later. It isn't always possible to define an interface in an abstract class, but in the light of evolution you should consider whether an abstract class is sufficient.&lt;br /&gt;
&lt;br /&gt;
Since changing interfaces breaks clients you should consider them as immutable once you've published them. As a consequence when adding a new method to an interface you have to do so in a separate interface. In Eclipse we take API stability seriously and for this reason you will find so called I*2 interfaces like IMarkerResolution2 or IWorkbenchPart2 in our APIs. These interfaces add methods to the base interfaces IMarkerResolution and IWorkbenchPart. Since the additions are done in separate extension interfaces you do not break the clients. However, there is now some burden on the caller in that they need to determine at run- time whether an object implements a particular extension interface.&lt;br /&gt;
&lt;br /&gt;
Another lesson learned is that you should focus not only on developing version one, but to also think about the following versions. This doesn't mean designing in future extensibility, but just keeping in mind that you have to maintain what you produce and try to keep the API stable for a long time. You want to build to last. That's been an important theme of Eclipse development since we started. We have built Eclipse as a platform. We always keep in mind as we design Eclipse that it has to last ten or twenty years. This can be scary at times.&lt;br /&gt;
&lt;br /&gt;
We added support for evolution in the base platform when we started. One example of this is the IAdaptable interface. Classes implementing this interface can be adapted to another interface. This is an example of the Extension Object pattern,. [4]&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69879</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69879"/>
		<updated>2012-11-17T15:38:59Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Requirements==&lt;br /&gt;
The introduction to the GoF book gives three principles for writing reusable and flexible software.&lt;br /&gt;
* Program to an interface, not an implementation.&lt;br /&gt;
* Favor object composition over class inheritance.&lt;br /&gt;
* Consider what should be variable in your design (originally, Encapsulate the behavior that varies).&lt;br /&gt;
&lt;br /&gt;
Explain these principles, and illustrate them with original examples.&lt;br /&gt;
&lt;br /&gt;
==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app. It's easy to add a dependency on a class. It's almost too easy; just add an import statement and modern Java development tools like Eclipse even write this statement for you. Interestingly the inverse isn't that easy and getting rid of an unwanted dependency can be real refactoring work or even worse, block you from reusing the code in another context. For this reason you have to develop with open eyes when it comes to introducing dependencies. This principle tells us that depending on an interface is often beneficial.&lt;br /&gt;
&lt;br /&gt;
Once you depend on interfaces only, you're decoupled from the implementation. That means the implementation can vary, and that's a healthy dependency relationship. For example, for testing purposes you can replace a heavy database implementation with a lighter-weight mock implementation. Fortunately, with today's refactoring support you no longer have to come up with an interface up front. You can distill an interface from a concrete class once you have the full insights into a problem. The intended interface is just one 'extract interface' refactoring away.&lt;br /&gt;
&lt;br /&gt;
So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. One question is whether you should always use a Java interfaces for that. An abstract class is good as well. In fact, an abstract class gives you more flexibility when it comes to evolution. You can add new behavior without breaking clients.&lt;br /&gt;
&lt;br /&gt;
In Java when you add a new method to an interface, you break all your clients. When you have an abstract class, you can add a new method and provide a default implementation in it. All the clients will continue to work. As always there is a trade-off, an interface gives you freedom with regard to the base class, an abstract class gives you the freedom to add new methods later. It isn't always possible to define an interface in an abstract class, but in the light of evolution you should consider whether an abstract class is sufficient.&lt;br /&gt;
&lt;br /&gt;
Since changing interfaces breaks clients you should consider them as immutable once you've published them. As a consequence when adding a new method to an interface you have to do so in a separate interface. In Eclipse we take API stability seriously and for this reason you will find so called I*2 interfaces like IMarkerResolution2 or IWorkbenchPart2 in our APIs. These interfaces add methods to the base interfaces IMarkerResolution and IWorkbenchPart. Since the additions are done in separate extension interfaces you do not break the clients. However, there is now some burden on the caller in that they need to determine at run- time whether an object implements a particular extension interface.&lt;br /&gt;
&lt;br /&gt;
Another lesson learned is that you should focus not only on developing version one, but to also think about the following versions. This doesn't mean designing in future extensibility, but just keeping in mind that you have to maintain what you produce and try to keep the API stable for a long time. You want to build to last. That's been an important theme of Eclipse development since we started. We have built Eclipse as a platform. We always keep in mind as we design Eclipse that it has to last ten or twenty years. This can be scary at times.&lt;br /&gt;
&lt;br /&gt;
We added support for evolution in the base platform when we started. One example of this is the IAdaptable interface. Classes implementing this interface can be adapted to another interface. This is an example of the Extension Object pattern,. [4]&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69547</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69547"/>
		<updated>2012-11-15T19:16:49Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app. It's easy to add a dependency on a class. It's almost too easy; just add an import statement and modern Java development tools like Eclipse even write this statement for you. Interestingly the inverse isn't that easy and getting rid of an unwanted dependency can be real refactoring work or even worse, block you from reusing the code in another context. For this reason you have to develop with open eyes when it comes to introducing dependencies. This principle tells us that depending on an interface is often beneficial.&lt;br /&gt;
&lt;br /&gt;
Once you depend on interfaces only, you're decoupled from the implementation. That means the implementation can vary, and that's a healthy dependency relationship. For example, for testing purposes you can replace a heavy database implementation with a lighter-weight mock implementation. Fortunately, with today's refactoring support you no longer have to come up with an interface up front. You can distill an interface from a concrete class once you have the full insights into a problem. The intended interface is just one 'extract interface' refactoring away.&lt;br /&gt;
&lt;br /&gt;
So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. One question is whether you should always use a Java interfaces for that. An abstract class is good as well. In fact, an abstract class gives you more flexibility when it comes to evolution. You can add new behavior without breaking clients.&lt;br /&gt;
&lt;br /&gt;
In Java when you add a new method to an interface, you break all your clients. When you have an abstract class, you can add a new method and provide a default implementation in it. All the clients will continue to work. As always there is a trade-off, an interface gives you freedom with regard to the base class, an abstract class gives you the freedom to add new methods later. It isn't always possible to define an interface in an abstract class, but in the light of evolution you should consider whether an abstract class is sufficient.&lt;br /&gt;
&lt;br /&gt;
Since changing interfaces breaks clients you should consider them as immutable once you've published them. As a consequence when adding a new method to an interface you have to do so in a separate interface. In Eclipse we take API stability seriously and for this reason you will find so called I*2 interfaces like IMarkerResolution2 or IWorkbenchPart2 in our APIs. These interfaces add methods to the base interfaces IMarkerResolution and IWorkbenchPart. Since the additions are done in separate extension interfaces you do not break the clients. However, there is now some burden on the caller in that they need to determine at run- time whether an object implements a particular extension interface.&lt;br /&gt;
&lt;br /&gt;
Another lesson learned is that you should focus not only on developing version one, but to also think about the following versions. This doesn't mean designing in future extensibility, but just keeping in mind that you have to maintain what you produce and try to keep the API stable for a long time. You want to build to last. That's been an important theme of Eclipse development since we started. We have built Eclipse as a platform. We always keep in mind as we design Eclipse that it has to last ten or twenty years. This can be scary at times.&lt;br /&gt;
&lt;br /&gt;
We added support for evolution in the base platform when we started. One example of this is the IAdaptable interface. Classes implementing this interface can be adapted to another interface. This is an example of the Extension Object pattern,. [4]&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/ &amp;lt;br&amp;gt;&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&amp;lt;br&amp;gt;&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69546</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69546"/>
		<updated>2012-11-15T19:16:17Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app. It's easy to add a dependency on a class. It's almost too easy; just add an import statement and modern Java development tools like Eclipse even write this statement for you. Interestingly the inverse isn't that easy and getting rid of an unwanted dependency can be real refactoring work or even worse, block you from reusing the code in another context. For this reason you have to develop with open eyes when it comes to introducing dependencies. This principle tells us that depending on an interface is often beneficial.&lt;br /&gt;
&lt;br /&gt;
Once you depend on interfaces only, you're decoupled from the implementation. That means the implementation can vary, and that's a healthy dependency relationship. For example, for testing purposes you can replace a heavy database implementation with a lighter-weight mock implementation. Fortunately, with today's refactoring support you no longer have to come up with an interface up front. You can distill an interface from a concrete class once you have the full insights into a problem. The intended interface is just one 'extract interface' refactoring away.&lt;br /&gt;
&lt;br /&gt;
So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. One question is whether you should always use a Java interfaces for that. An abstract class is good as well. In fact, an abstract class gives you more flexibility when it comes to evolution. You can add new behavior without breaking clients.&lt;br /&gt;
&lt;br /&gt;
In Java when you add a new method to an interface, you break all your clients. When you have an abstract class, you can add a new method and provide a default implementation in it. All the clients will continue to work. As always there is a trade-off, an interface gives you freedom with regard to the base class, an abstract class gives you the freedom to add new methods later. It isn't always possible to define an interface in an abstract class, but in the light of evolution you should consider whether an abstract class is sufficient.&lt;br /&gt;
&lt;br /&gt;
Since changing interfaces breaks clients you should consider them as immutable once you've published them. As a consequence when adding a new method to an interface you have to do so in a separate interface. In Eclipse we take API stability seriously and for this reason you will find so called I*2 interfaces like IMarkerResolution2 or IWorkbenchPart2 in our APIs. These interfaces add methods to the base interfaces IMarkerResolution and IWorkbenchPart. Since the additions are done in separate extension interfaces you do not break the clients. However, there is now some burden on the caller in that they need to determine at run- time whether an object implements a particular extension interface.&lt;br /&gt;
&lt;br /&gt;
Another lesson learned is that you should focus not only on developing version one, but to also think about the following versions. This doesn't mean designing in future extensibility, but just keeping in mind that you have to maintain what you produce and try to keep the API stable for a long time. You want to build to last. That's been an important theme of Eclipse development since we started. We have built Eclipse as a platform. We always keep in mind as we design Eclipse that it has to last ten or twenty years. This can be scary at times.&lt;br /&gt;
&lt;br /&gt;
We added support for evolution in the base platform when we started. One example of this is the IAdaptable interface. Classes implementing this interface can be adapted to another interface. This is an example of the Extension Object pattern,. [4]&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/&lt;br /&gt;
http://www.artima.com/lejava/articles/designprinciples.html&lt;br /&gt;
http://www.amazon.com/gp/product/0596007124?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0596007124&lt;br /&gt;
http://www.amazon.com/gp/product/0201633612?ie=UTF8&amp;amp;tag=fatagnus-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=0201633612&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69545</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69545"/>
		<updated>2012-11-15T19:13:00Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app. It's easy to add a dependency on a class. It's almost too easy; just add an import statement and modern Java development tools like Eclipse even write this statement for you. Interestingly the inverse isn't that easy and getting rid of an unwanted dependency can be real refactoring work or even worse, block you from reusing the code in another context. For this reason you have to develop with open eyes when it comes to introducing dependencies. This principle tells us that depending on an interface is often beneficial.&lt;br /&gt;
&lt;br /&gt;
Once you depend on interfaces only, you're decoupled from the implementation. That means the implementation can vary, and that's a healthy dependency relationship. For example, for testing purposes you can replace a heavy database implementation with a lighter-weight mock implementation. Fortunately, with today's refactoring support you no longer have to come up with an interface up front. You can distill an interface from a concrete class once you have the full insights into a problem. The intended interface is just one 'extract interface' refactoring away.&lt;br /&gt;
&lt;br /&gt;
So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. One question is whether you should always use a Java interfaces for that. An abstract class is good as well. In fact, an abstract class gives you more flexibility when it comes to evolution. You can add new behavior without breaking clients.&lt;br /&gt;
&lt;br /&gt;
In Java when you add a new method to an interface, you break all your clients. When you have an abstract class, you can add a new method and provide a default implementation in it. All the clients will continue to work. As always there is a trade-off, an interface gives you freedom with regard to the base class, an abstract class gives you the freedom to add new methods later. It isn't always possible to define an interface in an abstract class, but in the light of evolution you should consider whether an abstract class is sufficient.&lt;br /&gt;
&lt;br /&gt;
Since changing interfaces breaks clients you should consider them as immutable once you've published them. As a consequence when adding a new method to an interface you have to do so in a separate interface. In Eclipse we take API stability seriously and for this reason you will find so called I*2 interfaces like IMarkerResolution2 or IWorkbenchPart2 in our APIs. These interfaces add methods to the base interfaces IMarkerResolution and IWorkbenchPart. Since the additions are done in separate extension interfaces you do not break the clients. However, there is now some burden on the caller in that they need to determine at run- time whether an object implements a particular extension interface.&lt;br /&gt;
&lt;br /&gt;
Another lesson learned is that you should focus not only on developing version one, but to also think about the following versions. This doesn't mean designing in future extensibility, but just keeping in mind that you have to maintain what you produce and try to keep the API stable for a long time. You want to build to last. That's been an important theme of Eclipse development since we started. We have built Eclipse as a platform. We always keep in mind as we design Eclipse that it has to last ten or twenty years. This can be scary at times.&lt;br /&gt;
&lt;br /&gt;
We added support for evolution in the base platform when we started. One example of this is the IAdaptable interface. Classes implementing this interface can be adapted to another interface. This is an example of the Extension Object pattern,. [4]&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
==Consider what should be variable in your design==&lt;br /&gt;
==REFERENCES==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
http://www.fatagnus.com/program-to-an-interface-not-an-implementation/&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69544</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69544"/>
		<updated>2012-11-15T19:09:59Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Program to an interface, not an implementation==&lt;br /&gt;
This principle is really about dependency relationships which have to be carefully managed in a large app. It's easy to add a dependency on a class. It's almost too easy; just add an import statement and modern Java development tools like Eclipse even write this statement for you. Interestingly the inverse isn't that easy and getting rid of an unwanted dependency can be real refactoring work or even worse, block you from reusing the code in another context. For this reason you have to develop with open eyes when it comes to introducing dependencies. This principle tells us that depending on an interface is often beneficial.&lt;br /&gt;
&lt;br /&gt;
Once you depend on interfaces only, you're decoupled from the implementation. That means the implementation can vary, and that's a healthy dependency relationship. For example, for testing purposes you can replace a heavy database implementation with a lighter-weight mock implementation. Fortunately, with today's refactoring support you no longer have to come up with an interface up front. You can distill an interface from a concrete class once you have the full insights into a problem. The intended interface is just one 'extract interface' refactoring away.&lt;br /&gt;
&lt;br /&gt;
So this approach gives you flexibility, but it also separates the really valuable part, the design, from the implementation, which allows clients to be decoupled from the implementation. One question is whether you should always use a Java interfaces for that. An abstract class is good as well. In fact, an abstract class gives you more flexibility when it comes to evolution. You can add new behavior without breaking clients.&lt;br /&gt;
&lt;br /&gt;
In Java when you add a new method to an interface, you break all your clients. When you have an abstract class, you can add a new method and provide a default implementation in it. All the clients will continue to work. As always there is a trade-off, an interface gives you freedom with regard to the base class, an abstract class gives you the freedom to add new methods later. It isn't always possible to define an interface in an abstract class, but in the light of evolution you should consider whether an abstract class is sufficient.&lt;br /&gt;
&lt;br /&gt;
Since changing interfaces breaks clients you should consider them as immutable once you've published them. As a consequence when adding a new method to an interface you have to do so in a separate interface. In Eclipse we take API stability seriously and for this reason you will find so called I*2 interfaces like IMarkerResolution2 or IWorkbenchPart2 in our APIs. These interfaces add methods to the base interfaces IMarkerResolution and IWorkbenchPart. Since the additions are done in separate extension interfaces you do not break the clients. However, there is now some burden on the caller in that they need to determine at run- time whether an object implements a particular extension interface.&lt;br /&gt;
&lt;br /&gt;
Another lesson learned is that you should focus not only on developing version one, but to also think about the following versions. This doesn't mean designing in future extensibility, but just keeping in mind that you have to maintain what you produce and try to keep the API stable for a long time. You want to build to last. That's been an important theme of Eclipse development since we started. We have built Eclipse as a platform. We always keep in mind as we design Eclipse that it has to last ten or twenty years. This can be scary at times.&lt;br /&gt;
&lt;br /&gt;
We added support for evolution in the base platform when we started. One example of this is the IAdaptable interface. Classes implementing this interface can be adapted to another interface. This is an example of the Extension Object pattern,. [4]&lt;br /&gt;
&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
==Consider what should be variable in your design==&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69543</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w22 sk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w22_sk&amp;diff=69543"/>
		<updated>2012-11-15T19:07:07Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: Created page with &amp;quot;==Program to an interface, not an implementation== ==Favor object composition over class inheritance== ==Consider what should be variable in your design==&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Program to an interface, not an implementation==&lt;br /&gt;
==Favor object composition over class inheritance==&lt;br /&gt;
==Consider what should be variable in your design==&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012&amp;diff=69542</id>
		<title>CSC/ECE 517 Fall 2012</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012&amp;diff=69542"/>
		<updated>2012-11-15T18:58:49Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE_517_Fall_2012/Table_Of_Contents]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 n xx]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w1 rk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w20 pp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w5 su]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w6 pp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w4 aj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w7 am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w8 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w9 av]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w10 pk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w11 ap]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w12 mv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w14 gv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w17 ir]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w18 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w22 an]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w21 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w21 wi]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w31 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w16 br]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w23 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w24 nr]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w15 rt]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w3 pl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w32 cm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w5 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w37 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w67 ks]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w27 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w29 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w33 op]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w19 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w34 vd]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w35 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w30 rp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w58 am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w47 sk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w69 mv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w44 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w45 is]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w53 kc]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w40 ar]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w39 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w54 go]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w56 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w64 nn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w66 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w40 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w42 js]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w46 sm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w71 gs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w63 dv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w55 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w57 mp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w52 an]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch1b 1w38 nm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w60 ac]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w62 rb]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w29 st]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w3_sm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w30 an]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w17 pt]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w31 up]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w9 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w19 is]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w26 aj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w5 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w16 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w8 vp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w18 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w3 jm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w23 sr]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w11_aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w15 rr]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w33 pv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w20_aa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w14_bb]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w21_ap]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w13_sm]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w4_sa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w25_nr]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w12_sv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w7_ma]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w6_ar]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w32_mk]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w10_rc]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w70_sm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w67_sk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w40_sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w22_sk]]&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w1_rk&amp;diff=62939</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w1 rk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w1_rk&amp;diff=62939"/>
		<updated>2012-09-08T00:37:55Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Concurrent Versions System (CVS)http://en.wikipedia.org/wiki/Concurrent_Versions_System */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Revision_control version control] system '''(VCS)''' is a process for managing software codes,files and directory structures and corresponding updates made to them during software development, web development etc. project or during subsequent project maintenances. Version control is also known as revision control, source control or [http://en.wikipedia.org/wiki/Software_configuration_management software configuration management] (SCM)[6].&lt;br /&gt;
&lt;br /&gt;
Any software development project is a dynamic and fast paced environment. In a typical setting, development for a project is performed simultaneously by many developers. Thus, incorporating all the changes made, either simultaneously or at different times, poses a new type of challenge. &lt;br /&gt;
&lt;br /&gt;
This wikibook chapter focuses mainly on the development history of different version control systems.&lt;br /&gt;
&lt;br /&gt;
==Why version control systems are needed?==&lt;br /&gt;
The major issues in a dynamic development environment can be described as:&lt;br /&gt;
* Obviously, '''merging''' of a lot of files. If we consider somebody to do merging manually, The sheer volume of communication required is overwhelming. This communication can be among the developers themselves in a small team or between the team leader in charge of merging and the rest of the group.&lt;br /&gt;
&lt;br /&gt;
* '''Accountability:''' if one of the developers breaks the code flow during development, It is tough to detect and naturally nobody steps forward to take the blame. A version control system can precisely indicate who caused the break in the code.&lt;br /&gt;
&lt;br /&gt;
* If a certain code implementation doesn't work as expected, '''Reverting''' to last satisfactory state may be required. &lt;br /&gt;
&lt;br /&gt;
* Development on stale code may result in '''Code loss'''. for example, two developers downloaded a certain file at 10AM. One of the developers modified foo_1() method and uploaded modified file at 10:30AM.The other developer modified foo_2() method and uploaded the same file at 10:45AM. Since the functions are in the same file, the second upload will overwrite the file uploaded by first developer at 10:30AM causing loss of his part of work.    &lt;br /&gt;
&lt;br /&gt;
* Even a lone coder might need to '''review''' why he or she made a certain change in code. Comments during code check-in can be a useful resource in such situation. &lt;br /&gt;
&lt;br /&gt;
* Version control provides a form of '''documentation''' which makes tracking easy. i.e.-'''tagging''' is a kind of snapshot of all files and documents at a particular stage of development, usually during a stable release. This allows the developers to work with the exact files that were included in that release for bug-fixing purpose. &lt;br /&gt;
&lt;br /&gt;
* '''Sandboxing / Branching:''' Version control makes it possible to perform temporary code changes in an isolated area, usually in branch folder, for testing purpose. If the outcome is satisfactory then the code can be merged with the existing code, otherwise it can be discarded without having any impact on the main code.&lt;br /&gt;
&lt;br /&gt;
* Now a days, software development teams are spread across different countries and work at different time zones. Use of a version control system for project aggregation becomes unavoidable.&lt;br /&gt;
 &lt;br /&gt;
==Evolution of version control systems==&lt;br /&gt;
&lt;br /&gt;
VCS' can be broadly categorized into three groups based on the repository model. The sequence below follows the evolution of version control systems as well: &lt;br /&gt;
&lt;br /&gt;
==='''Local repository model''' &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Source_Code_Control_System&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Local version control systems had one storage location of the files. It was called local because it didn't support networked commands or access like the other later softwares. So, all the developers had to use same computer system to access or modify files.  &lt;br /&gt;
&lt;br /&gt;
===='''Source Code Control System (SCCS)'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Source_Code_Control_System&amp;lt;/ref&amp;gt;==== &lt;br /&gt;
It is one of the pioneer source code revision softwares.[5] SCCS was developed at Bell Labs in 1972 by Marc J. Rochkind. Although it was originally developed for OS/MVT, SCCS was included in [http://en.wikipedia.org/wiki/Source_Code_Control_System some UNIX distributions.] SCCS ruled as the dominant VCS until ''Revision Control System'' was released.&lt;br /&gt;
:SCCS was the dominant version control system for Unix until the release of the [http://en.wikipedia.org/wiki/Revision_Control_System Revision Control System (RCS)]. Today, SCCS is generally considered obsolete. However, its file format is still used internally by a few other revision control programs, including [http://en.wikipedia.org/wiki/BitKeeper BitKeeper] and [http://en.wikipedia.org/wiki/TeamWare TeamWare]. The latter is a frontend to SCCS. [http://en.wikipedia.org/wiki/Sablime Sablime] has been developed from a modified version of SCCS but uses a history file format that is incompatible with SCCS. The SCCS file format uses a storage technique called [http://en.wikipedia.org/wiki/Interleaved_deltas interleaved deltas] (or the weave). This storage technique is now considered by many [http://en.wikipedia.org/wiki/Revision_control revision control] system developers as foundational to advanced merging and versioning techniques, such as the &amp;quot;Precise [http://en.wikipedia.org/wiki/Codeville Codeville]&amp;quot; (&amp;quot;pcdv&amp;quot;) merge.&lt;br /&gt;
:'''What does a source code control system do?'''&lt;br /&gt;
:If you are creating or maintaining a text file---perhaps a document, or a script, or a program---a source code control system can do several things for you:&lt;br /&gt;
:*It can keep track of the changes made to the file: what was changed, when it was changed, and by whom.&lt;br /&gt;
:*It provides a version numbering scheme so you can tell which versions of a file are more recent.&lt;br /&gt;
:*It can retrieve previous versions of your file, so that you can retreat to an older version if you decide that the current version is a bad idea, or if you want to see some text that has since been changed or deleted.&lt;br /&gt;
:*If you accidentally delete the current file, you can get back the last version.&lt;br /&gt;
:*If several people are working with the same file, a source code control system can help you coordinate your work and keep track of who did what, and when.&lt;br /&gt;
&lt;br /&gt;
SCCS is also known for the &amp;lt;code&amp;gt;sccsid&amp;lt;/code&amp;gt; string, for example:&lt;br /&gt;
&lt;br /&gt;
 static char sccsid[] = &amp;quot;@(#)ls.c        8.1 (Berkeley) 6/11/93&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
This string contains the file name, date, and can also contain a comment. After compilation, this string can be found in binary and object files by looking for the pattern &amp;quot;@(#)&amp;quot; and can be used determine which source code files were used during compilation.&lt;br /&gt;
&lt;br /&gt;
===='''Control System(RCS)'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Revision_Control_System Revision&amp;lt;/ref&amp;gt;==== &lt;br /&gt;
It automated storing, retrieval, logging, identification, and merging frequent revisions of texts. RCS was first released in 1982 by Walter F. Tichy as an alternative to SCCS. It quickly gained popularity and almost replaced SCCS.[9] &lt;br /&gt;
:RCS performed better by storing the most recent copy of file and then storing only reverse differences called &amp;quot;deltas&amp;quot;.One of the shortcomings of RCS was that only one person at a time could edit the file. RCS could manage only single files, not a whole project or directory.&lt;br /&gt;
:Ref.[3] is a comprehensive book on CSSC and RCS.&lt;br /&gt;
&lt;br /&gt;
==='''Client-server model'''===&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Client%E2%80%93server_model client-server model] utilizes a single centralized repository for the version control which is accessible to the developers through network or internet. The below diagram [http://svnbook.red-bean.com/en/1.7/svn.basic.version-control-basics.html] provides a high level overview of the model.&lt;br /&gt;
[[Image:Client_Server_Model.png |center|]]&lt;br /&gt;
===='''Concurrent Versions System (CVS)'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Concurrent_Versions_System&amp;lt;/ref&amp;gt;====&lt;br /&gt;
It was one of the early client-server model based scheme. Dick Grune started developing CVS from 1984-1985 to allow his students to collaborate in a project according to their schedule. CVS was publicly released at 1986.The main improvement for CVS over RCS was that CVS could manage the whole project while RCS could only work on a file at a time.At the beginning, CVS was script based and called RCS at background. Later it was developed into a full fledged program. A lot of the IDE's (Emacs, Eclipse/aptana,Netbeans, Komodo, PHPEdit etc.) support CVS. CVSNT is a cross platform port of CVS with some modification. CVS, which was the defacto standard for version controlling for a long time is almost replaced today by SVN. There were many disadvantages of CVS which hindered its stay in the industry further. Prominent ones were&lt;br /&gt;
#CVS check-in is not an [http://en.wikipedia.org/wiki/Atomic_commit atomic] operation. For example, given the files 1.c, 2.c, 3.c, 4.c and if someone runs '''cvs ci 1.c 3.c''' and someone else runs cvs update at the same time, the person running update might get only the change to `3.c' and not the change to `1.c'. So, if check-in process was disturbed, it could result in damage of existing project at repository.&lt;br /&gt;
#CVS only tracks modification on a file-by-file basis.&lt;br /&gt;
#CVS was designed with only text files in mind. No native support for other formats. Extensive modification are necessary at the client and the server to support other file types.&lt;br /&gt;
#Conflict resolution in CVS, if not absent, is definitely not good. Conflict markers used in CVS may go unnoticed and those file might find their way into the repository.&lt;br /&gt;
#Slow&lt;br /&gt;
&lt;br /&gt;
===='''Subversion (SVN)'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Subversion_%28software%29&amp;lt;/ref&amp;gt;==== &lt;br /&gt;
As the complexity of projects increased, the shortcomings of CVS became more and more prominent. This led to the development of Subversion. CollabNet started developing svn as a successor of CVS with added [http://en.wikipedia.org/wiki/Subversion_(software)#Features functionality][2][7]. Different open source projects (i.e.-[http://en.wikipedia.org/wiki/Apache_Software_Foundation Apache Software  Foundation],[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby],[http://en.wikipedia.org/wiki/SourceForge SourceForge],[http://en.wikipedia.org/wiki/Tigris.org Tigris.org], [http://en.wikipedia.org/wiki/PHP PHP],  [http://en.wikipedia.org/wiki/Python_(programming_language) Python] and [http://en.wikipedia.org/wiki/MediaWiki MediaWiki]) use Subversion. Subversion is an open source software due to it's Apache license[1].&lt;br /&gt;
[[Image:Subversion_project_visualization.svg.png|650px|thumb|center|Visualization of a very simple Subversion project. Source:wikimedia commons, Explanation of terms can be found at http://en.wikipedia.org/wiki/Apache_Subversion, &amp;quot;Branching and tagging&amp;quot; and at http://en.wikipedia.org/wiki/Revision_control, #&amp;quot;Common vocabulary&amp;quot;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Features:''' &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Subversion#Features&amp;lt;/ref&amp;gt;&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Commit_(data_management) Commits] as true [http://en.wikipedia.org/wiki/Atomicity_(database_systems) atomic operations] (interrupted commit operations in CVS would cause repository inconsistency or corruption).&lt;br /&gt;
* Renamed/copied/moved/removed files retain full revision history.&lt;br /&gt;
* The system maintains [http://en.wikipedia.org/wiki/Software_versioning versioning] for directories, renames, and file [http://en.wikipedia.org/wiki/Metadata metadata] (but not for timestamps). Users can move and/or copy entire directory-trees very quickly, while retaining full revision history.&lt;br /&gt;
* Versioning of [http://en.wikipedia.org/wiki/Symbolic_link symbolic link]s.&lt;br /&gt;
* Native support for binary files, with space-efficient binary-diff storage.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Apache_HTTP_Server Apache HTTP Server] as network server, [http://en.wikipedia.org/wiki/WebDAV WebDAV]/[http://en.wikipedia.org/wiki/WebDAV#Extensions_and_derivatives Delta-V] for protocol. There is also an independent server [http://en.wikipedia.org/wiki/Process_(computing) process] called svnserve that uses a custom protocol over [http://en.wikipedia.org/wiki/Internet_Protocol_Suite TCP/IP].&lt;br /&gt;
* [[Branching (software)|Branching]] as a cheap operation, independent of file size (though Subversion itself does not distinguish between a branch and a directory)&lt;br /&gt;
* Natively [http://en.wikipedia.org/wiki/Client%E2%80%93server_model client–server], [http://en.wikipedia.org/wiki/Abstraction_layer layered] [http://en.wikipedia.org/wiki/Library_(computing) library] design.&lt;br /&gt;
* Client/server protocol sends [[diff]]s in both directions.&lt;br /&gt;
* Costs proportional to change size, not to data size.&lt;br /&gt;
* [[Parsing|Parsable]] output, including [[XML]] log output.&lt;br /&gt;
* [[Open source]] licensed — [[Apache License]] in the projected 1.7 release; prior versions use a derivative of the Apache Software License, v1.1&lt;br /&gt;
* [[Internationalization and localization|Internationalized]] program messages.&lt;br /&gt;
* [[File locking]] for unmergeable files (&amp;quot;reserved checkouts&amp;quot;).&lt;br /&gt;
* Path-based authorization.&lt;br /&gt;
* [[Language binding]]s for [[C Sharp (programming language)|C#]], [[PHP]], [[Python (programming language)|Python]], [[Perl]], [[Ruby (programming language)|Ruby]], and [[Java (programming language)|Java]].&lt;br /&gt;
* Full [[MIME]] support — users can view or change the MIME type of each file, with the software knowing which MIME types can have their differences from previous versions shown.&lt;br /&gt;
* Merge tracking - Merges between branches will be tracked, this allows automatically merging between branches without telling Subversion what (doesn't) need to be merged.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====Eclipse Subversive - Subversion (SVN) Team Provider&amp;lt;ref&amp;gt;http://www.eclipse.org/subversive/&amp;lt;/ref&amp;gt;=====&lt;br /&gt;
The Subversive project is aimed to integrate the Subversion (SVN) version control system with the Eclipse platform. Using the Subversive plug-in, you can work with projects stored in Subversion repositories directly from the Eclipse workbench in a way similar to work with other Eclipse version control providers, such as CVS and Git.&lt;br /&gt;
&lt;br /&gt;
'''Subversive Features''': Subversive plug-in provides access to Subversion repositories from the Eclipse workbench.&lt;br /&gt;
&lt;br /&gt;
*'''Full-Scale SVN Client'''&lt;br /&gt;
:Subversive is designed to be used as a full-featured SVN client, so you can update, commit, merge changes, work with SVN properties, view change history and perform other operations with SVN directly from the Eclipse environment.&lt;br /&gt;
   	&lt;br /&gt;
*'''Advanced SVN Features'''&lt;br /&gt;
:Subversive includes several features that extend functionality of the standard SVN client. In particular, Subversive can show the SVN repository content grouped by the logical structures of trunk, branch and tag and display changes on a visual revisions graph.&lt;br /&gt;
&lt;br /&gt;
*'''Seamless Integration with Eclipse'''&lt;br /&gt;
:Subversive is an official Eclipse project and an integral part of Eclipse Simultaneous releases. The project follows all Eclipse guidelines and requirements to deliver a quality SVN team provider plug-in similar to CVS and Git implementations.&lt;br /&gt;
   	&lt;br /&gt;
*'''Support of the Latest SVN Versions'''&lt;br /&gt;
:Subversive evolves together with the Subversion project to provide Eclipse users with the features that appeared in new versions of the SVN implementation. You can use the new SVN functionality in Eclipse by installing the Early Access version of Subversive.&lt;br /&gt;
&lt;br /&gt;
===='''Configuration Management Version Control (CMVC)'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/IBM_Configuration_Management_Version_Control_(CMVC)&amp;lt;/ref&amp;gt;==== &lt;br /&gt;
It was developed by IBM Corporation in the mid-late 1990s and was derived in part from software purchased from HP and from IBM's internal-use-only system, IDSS. CMVC was superseded by IBM Rational ClearCase and ClearQuest. The system was used to manage the IBM OS/2 and IBM AIX source code repositories in the 1990s. It is still widely used within IBM by various teams. &lt;br /&gt;
&lt;br /&gt;
One of the drawbacks of CMVC is that, once a file is checked-out by a user, it remains locked to all the other users until the either the new version is checked-in or the lock is released explicitly by the owner (user) of the lock. Some proprietary client-server based version control softwares are:&lt;br /&gt;
::*[http://en.wikipedia.org/wiki/Autodesk_Vault Autodesk Vault] was specifically developed for Autodesk applications.&lt;br /&gt;
::*[http://en.wikipedia.org/wiki/IBM_Rational_ClearCase ClearCase] was developed by IBM Rational Software. It's a Source Code Control (SCC) compliant software.&lt;br /&gt;
::*[http://en.wikipedia.org/wiki/Visual_SourceSafe Visual SourceSafe] is developed by Microsoft targeting small development team.&lt;br /&gt;
::*[http://en.wikipedia.org/wiki/Visual_Studio_Team_System Visual Studio Team System] is also developed by Microsoft targeting larger groups.&lt;br /&gt;
&lt;br /&gt;
===Distributed model===&lt;br /&gt;
'''Distributed Version Control (DVCS)''', or '''Decentralized Version Control''' systems can have many central repositories.This is a peer to peer approach. The concept started developing at late 90's. In DVCS. Each developer works with his or her local repository and the changes are synchronized between repositories upon commit. DVCS are better suited for large teams with partially independent developers. i.e.- opensource software development.[8]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Monotone_%28software%29 Monotone] and [http://en.wikipedia.org/wiki/GNU_arch GNU arch]  were the first generation DVCS (release:2001-2003) followed by [http://en.wikipedia.org/wiki/Darcs Darcs] (stable release:2010).[http://en.wikipedia.org/wiki/Mercurial Mercurial] , [http://en.wikipedia.org/wiki/Git_%28software%29 Git] and [http://en.wikipedia.org/wiki/Bazaar_%28software%29 Bazaar] (2005-2007) are well adopted among developers.   &lt;br /&gt;
#[http://en.wikipedia.org/wiki/BitKeeper BitKeeper],[http://en.wikipedia.org/wiki/Code_Co-op Code Co-op], [http://en.wikipedia.org/wiki/Sun_WorkShop_TeamWare Sun WorkShop TeamWare] are some proprietary DVCS softwares.&lt;br /&gt;
&lt;br /&gt;
It should be noted that many distributed version control softwares support client-server model too.One of the benefits of DVCS is that a developer can save the source code as long as he wants even if the central repository (in client-server model) is discarded at the end of a project.&lt;br /&gt;
&lt;br /&gt;
[[Image:timeline.jpg|650px|thumb|center|A generalized timeline. Source:http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki1a_5_History_of_version_control_by_av]]&lt;br /&gt;
&lt;br /&gt;
== File Sharing Models ==&lt;br /&gt;
Every system that implement version controlling have to address one fundamental problem: How will the files in the repository be safely shared across users but prevent them from accidentally stepping on each other's feet? It's all too easy for users to accidentally overwrite each other's changes in the repository.&lt;br /&gt;
&lt;br /&gt;
Consider the scenario with two users A and B. Both of them check out the same file (same version). User A after making his modification, suppose, commits the file first. A few moments later B completes his modification. B does not have any clue about A's check-in and he happily commits his code to the repository. Now B has accidentally overwritten the changes made by A leaving the system in an inconsistent state. This problem can be solved in two different ways:&amp;lt;br/&amp;gt;&lt;br /&gt;
* Lock-Modify-Unlock&lt;br /&gt;
* Copy-Modify-Merge &amp;lt;br/&amp;gt;&lt;br /&gt;
While CMVC follows the lock-modify-unlock solution, svn follows copy-modify-merge allowing users to modify the same piece of code concurrently. &amp;lt;br/&amp;gt;&lt;br /&gt;
The problem with the lock-modify-unlock model is that it's a bit restrictive and often becomes a roadblock for users:&lt;br /&gt;
&lt;br /&gt;
* Locking may cause unnecessary delay and is not desired when it comes to teams/projects which have a small cycle time between releases. For example: Suppose say, user A checks out a file (locks it) and some interrupt in his work causes him to switch to another task of higher priority. There is a possibility that he forgets completely about the file that he checked out. Now, if another user B wants to edit the same file, he cannot do so, without having the administrator unlock the file for him, his hands are tied!&lt;br /&gt;
&lt;br /&gt;
* Locking may cause unnecessary serialization: What if two different users A and B want to edit different non-intersecting portions of the same file? With proper merging solution in place, they could have done it easily without bothering about what the other user does with the file.&lt;br /&gt;
&lt;br /&gt;
* Locking may create a false sense of security: As with any model, lock-modify-unlock approach too allows two different users to work on separate files simultaneously. However the model does not define how dependencies between files are dealt with.&amp;lt;br/&amp;gt;For example: Suppose A locks and edits file f1, while B simultaneously locks and edits file f2. If there is a function call in f1 whose definition exists in f2 but the definition is removed or the function name is changed after editing f2, they don't work together anymore.&amp;lt;br/&amp;gt;Thus, locking files by itself does not provide security against such deliberate changes. Lot of manual synchronization is needed to avoid such situations which is only going to cause delay in the development of the project.&lt;br /&gt;
&lt;br /&gt;
==Use of version control in other areas ==&lt;br /&gt;
&lt;br /&gt;
Now a days, many document editing softwares have adopted version control. Wikis, GoogleDoc, Microsoft Office and OpenOffice.org suite are some example softwares that can save previous document editing history. &lt;br /&gt;
&lt;br /&gt;
==Other considerations==&lt;br /&gt;
&lt;br /&gt;
Most open source softwares have [http://linuxmafia.com/faq/Apps/vcs.html distributions for Linux] OS. In most open source cases, Linux and windows versions are released concurrently. &lt;br /&gt;
Many VCS' have plugins for common IDEs like Eclipse, Visual Studio, Oracle JDeveloper etc. NetBeans IDE and Xcode has integrated version control support.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Additional References==&lt;br /&gt;
&lt;br /&gt;
1. [http://subversion.apache.org/news.html#news-20100217.  Apache Software Foundation Announcements, &amp;quot;Subversion becomes Apache Subversion&amp;quot;.(2010-02-17) Accessed:September 2010 ]&lt;br /&gt;
&lt;br /&gt;
2. [http://svnbook.red-bean.com/ Ben Collins-Sussman, Brian W. Fitzpatrick, C. Michael Pilato. &amp;quot;Version Control with Subversion&amp;quot;, an O'Reilly book available online. Accessed:September 2010] &lt;br /&gt;
&lt;br /&gt;
3. [http://shop.oreilly.com/product/9781565921177.do Don Bolinger, Tan Bronson: Applying RCS and SCCS. O'Reilly Media. ISBN:978-1-56592-117-7]  &lt;br /&gt;
&lt;br /&gt;
4. [http://www.ericsink.com/scm/source_control.html  Eric Sink: A collection of articles on source control and best practices, Accessed:September 2010]&lt;br /&gt;
&lt;br /&gt;
5. [http://basepath.com/aup/talks/SCCS-Slideshow.pdf  M. J. Rochkind: The Source Code Control System.] In IEEE Transactions on Software Engineering SE-1:4 (Dec. 1975), pages 364–370.&lt;br /&gt;
&lt;br /&gt;
6. [http://onlinelibrary.wiley.com/doi/10.1002/bltj.2039/pdf Martin, Robert L. (2002). &amp;quot;Software configuration management for the 21st century&amp;quot;. Bell Labs technical journal, Volume 2, Issue 1, page- 154.]&lt;br /&gt;
&lt;br /&gt;
7. Mike Mason; Pragmatic Version Control Using Subversion; Pragmatic Bookshelf; ISBN 0-9745140-6-3 (1st edition, paperback, 2005)&lt;br /&gt;
&lt;br /&gt;
8. [http://www.ibm.com/developerworks/aix/library/au-dist_ver_control/ Noah Gift,Adam Shand: Introduction to distributed version control systems (compare how to use Bazaar, Mercurial, and Git) (Apr 2009), IBM Technical Library, Accessed:September 2010 ] &lt;br /&gt;
&lt;br /&gt;
9.[http://onlinelibrary.wiley.com/doi/10.1002/spe.4380150703/abstract Walter F. Tichy; Rcs - a system for version control; In Software: Practice and Experience. Volume 15, Issue 7,(July 1985) pages 637–654 ]&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Revision_control Wikipedia: Revision control]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/List_of_revision_control_software Wikipedia: List of revision control software]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Comparison_of_revision_control_software Wikipedia: Detail comparison of revision control softwares]&lt;br /&gt;
&lt;br /&gt;
[http://www.nongnu.org/cvs/ CVS webpage]&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.vu.nl/~dick/  Dick Grune's website on CVS history]&lt;br /&gt;
&lt;br /&gt;
[http://groups.google.com/group/mod.sources/msg/2ebab72ac0744fb8?dmode=source The original usenet post on CVS] archived at google groups.&lt;br /&gt;
&lt;br /&gt;
[http://linuxmafia.com/faq/Apps/vcs.html Linux availability of various version control softwares]&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w1_rk&amp;diff=62938</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w1 rk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w1_rk&amp;diff=62938"/>
		<updated>2012-09-07T23:50:00Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* Configuration Management Version Control (CMVC)http://en.wikipedia.org/wiki/IBM_Configuration_Management_Version_Control_(CMVC) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Revision_control version control] system '''(VCS)''' is a process for managing software codes,files and directory structures and corresponding updates made to them during software development, web development etc. project or during subsequent project maintenances. Version control is also known as revision control, source control or [http://en.wikipedia.org/wiki/Software_configuration_management software configuration management] (SCM)[6].&lt;br /&gt;
&lt;br /&gt;
Any software development project is a dynamic and fast paced environment. In a typical setting, development for a project is performed simultaneously by many developers. Thus, incorporating all the changes made, either simultaneously or at different times, poses a new type of challenge. &lt;br /&gt;
&lt;br /&gt;
This wikibook chapter focuses mainly on the development history of different version control systems.&lt;br /&gt;
&lt;br /&gt;
==Why version control systems are needed?==&lt;br /&gt;
The major issues in a dynamic development environment can be described as:&lt;br /&gt;
* Obviously, '''merging''' of a lot of files. If we consider somebody to do merging manually, The sheer volume of communication required is overwhelming. This communication can be among the developers themselves in a small team or between the team leader in charge of merging and the rest of the group.&lt;br /&gt;
&lt;br /&gt;
* '''Accountability:''' if one of the developers breaks the code flow during development, It is tough to detect and naturally nobody steps forward to take the blame. A version control system can precisely indicate who caused the break in the code.&lt;br /&gt;
&lt;br /&gt;
* If a certain code implementation doesn't work as expected, '''Reverting''' to last satisfactory state may be required. &lt;br /&gt;
&lt;br /&gt;
* Development on stale code may result in '''Code loss'''. for example, two developers downloaded a certain file at 10AM. One of the developers modified foo_1() method and uploaded modified file at 10:30AM.The other developer modified foo_2() method and uploaded the same file at 10:45AM. Since the functions are in the same file, the second upload will overwrite the file uploaded by first developer at 10:30AM causing loss of his part of work.    &lt;br /&gt;
&lt;br /&gt;
* Even a lone coder might need to '''review''' why he or she made a certain change in code. Comments during code check-in can be a useful resource in such situation. &lt;br /&gt;
&lt;br /&gt;
* Version control provides a form of '''documentation''' which makes tracking easy. i.e.-'''tagging''' is a kind of snapshot of all files and documents at a particular stage of development, usually during a stable release. This allows the developers to work with the exact files that were included in that release for bug-fixing purpose. &lt;br /&gt;
&lt;br /&gt;
* '''Sandboxing / Branching:''' Version control makes it possible to perform temporary code changes in an isolated area, usually in branch folder, for testing purpose. If the outcome is satisfactory then the code can be merged with the existing code, otherwise it can be discarded without having any impact on the main code.&lt;br /&gt;
&lt;br /&gt;
* Now a days, software development teams are spread across different countries and work at different time zones. Use of a version control system for project aggregation becomes unavoidable.&lt;br /&gt;
 &lt;br /&gt;
==Evolution of version control systems==&lt;br /&gt;
&lt;br /&gt;
VCS' can be broadly categorized into three groups based on the repository model. The sequence below follows the evolution of version control systems as well: &lt;br /&gt;
&lt;br /&gt;
==='''Local repository model''' &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Source_Code_Control_System&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Local version control systems had one storage location of the files. It was called local because it didn't support networked commands or access like the other later softwares. So, all the developers had to use same computer system to access or modify files.  &lt;br /&gt;
&lt;br /&gt;
===='''Source Code Control System (SCCS)'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Source_Code_Control_System&amp;lt;/ref&amp;gt;==== &lt;br /&gt;
It is one of the pioneer source code revision softwares.[5] SCCS was developed at Bell Labs in 1972 by Marc J. Rochkind. Although it was originally developed for OS/MVT, SCCS was included in [http://en.wikipedia.org/wiki/Source_Code_Control_System some UNIX distributions.] SCCS ruled as the dominant VCS until ''Revision Control System'' was released.&lt;br /&gt;
:SCCS was the dominant version control system for Unix until the release of the [http://en.wikipedia.org/wiki/Revision_Control_System Revision Control System (RCS)]. Today, SCCS is generally considered obsolete. However, its file format is still used internally by a few other revision control programs, including [http://en.wikipedia.org/wiki/BitKeeper BitKeeper] and [http://en.wikipedia.org/wiki/TeamWare TeamWare]. The latter is a frontend to SCCS. [http://en.wikipedia.org/wiki/Sablime Sablime] has been developed from a modified version of SCCS but uses a history file format that is incompatible with SCCS. The SCCS file format uses a storage technique called [http://en.wikipedia.org/wiki/Interleaved_deltas interleaved deltas] (or the weave). This storage technique is now considered by many [http://en.wikipedia.org/wiki/Revision_control revision control] system developers as foundational to advanced merging and versioning techniques, such as the &amp;quot;Precise [http://en.wikipedia.org/wiki/Codeville Codeville]&amp;quot; (&amp;quot;pcdv&amp;quot;) merge.&lt;br /&gt;
:'''What does a source code control system do?'''&lt;br /&gt;
:If you are creating or maintaining a text file---perhaps a document, or a script, or a program---a source code control system can do several things for you:&lt;br /&gt;
:*It can keep track of the changes made to the file: what was changed, when it was changed, and by whom.&lt;br /&gt;
:*It provides a version numbering scheme so you can tell which versions of a file are more recent.&lt;br /&gt;
:*It can retrieve previous versions of your file, so that you can retreat to an older version if you decide that the current version is a bad idea, or if you want to see some text that has since been changed or deleted.&lt;br /&gt;
:*If you accidentally delete the current file, you can get back the last version.&lt;br /&gt;
:*If several people are working with the same file, a source code control system can help you coordinate your work and keep track of who did what, and when.&lt;br /&gt;
&lt;br /&gt;
SCCS is also known for the &amp;lt;code&amp;gt;sccsid&amp;lt;/code&amp;gt; string, for example:&lt;br /&gt;
&lt;br /&gt;
 static char sccsid[] = &amp;quot;@(#)ls.c        8.1 (Berkeley) 6/11/93&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
This string contains the file name, date, and can also contain a comment. After compilation, this string can be found in binary and object files by looking for the pattern &amp;quot;@(#)&amp;quot; and can be used determine which source code files were used during compilation.&lt;br /&gt;
&lt;br /&gt;
===='''Control System(RCS)'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Revision_Control_System Revision&amp;lt;/ref&amp;gt;==== &lt;br /&gt;
It automated storing, retrieval, logging, identification, and merging frequent revisions of texts. RCS was first released in 1982 by Walter F. Tichy as an alternative to SCCS. It quickly gained popularity and almost replaced SCCS.[9] &lt;br /&gt;
:RCS performed better by storing the most recent copy of file and then storing only reverse differences called &amp;quot;deltas&amp;quot;.One of the shortcomings of RCS was that only one person at a time could edit the file. RCS could manage only single files, not a whole project or directory.&lt;br /&gt;
:Ref.[3] is a comprehensive book on CSSC and RCS.&lt;br /&gt;
&lt;br /&gt;
==='''Client-server model'''===&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Client%E2%80%93server_model client-server model] utilizes a single centralized repository for the version control which is accessible to the developers through network or internet. The below diagram [http://svnbook.red-bean.com/en/1.7/svn.basic.version-control-basics.html] provides a high level overview of the model.&lt;br /&gt;
[[Image:Client_Server_Model.png |center|]]&lt;br /&gt;
===='''Concurrent Versions System (CVS)'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Concurrent_Versions_System&amp;lt;/ref&amp;gt;====&lt;br /&gt;
It was one of the early client-server model based scheme. Dick Grune started developing CVS from 1984-1985 to allow his students to collaborate in a project according to their schedule. CVS was publicly released at 1986.The main improvement for CVS over RCS was that CVS could manage the whole project while RCS could only work on a file at a time.At the beginning, CVS was script based and called RCS at background. Later it was developed into a full fledged program. A lot of the IDE's (Emacs, Eclipse/aptana,Netbeans, Komodo, PHPEdit etc.) support CVS. CVSNT is a cross platform port of CVS with some modification. CVS, which was the defacto standard for version controlling for a long time is almost replaced today by SVN. There were many disadvantages of CVS which hindered its stay in the industry further. Prominent ones were&lt;br /&gt;
#CVS check-in is not an [http://en.wikipedia.org/wiki/Atomic_commit atomic] operation. For example, given the files 1.c, 2.c, 3.c, 4.c and if someone runs '''cvs ci 1.c 3.c''' and someone else runs cvs update at the same time, the person running update might get only the change to `3.c' and not the change to `1.c'. So, if check-in process was disturbed, it could result in damage of existing project at repository.&lt;br /&gt;
#CVS only tracks modification on a file-by-file basis. Not scalable for larger projects.&lt;br /&gt;
#CVS was designed with only text files in mind. No native support for other formats. Extensive modification are necessary at the client and the server to support other file types.&lt;br /&gt;
#Conflict resolution in CVS, if not absent, is definitely not good. Conflict markers used in CVS may go unnoticed and those file might find their way into the repository.&lt;br /&gt;
#Slow&lt;br /&gt;
&lt;br /&gt;
===='''Subversion (SVN)'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Subversion_%28software%29&amp;lt;/ref&amp;gt;==== &lt;br /&gt;
As the complexity of projects increased, the shortcomings of CVS became more and more prominent. This led to the development of Subversion. CollabNet started developing svn as a successor of CVS with added [http://en.wikipedia.org/wiki/Subversion_(software)#Features functionality][2][7]. Different open source projects (i.e.-[http://en.wikipedia.org/wiki/Apache_Software_Foundation Apache Software  Foundation],[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby],[http://en.wikipedia.org/wiki/SourceForge SourceForge],[http://en.wikipedia.org/wiki/Tigris.org Tigris.org], [http://en.wikipedia.org/wiki/PHP PHP],  [http://en.wikipedia.org/wiki/Python_(programming_language) Python] and [http://en.wikipedia.org/wiki/MediaWiki MediaWiki]) use Subversion. Subversion is an open source software due to it's Apache license[1].&lt;br /&gt;
[[Image:Subversion_project_visualization.svg.png|650px|thumb|center|Visualization of a very simple Subversion project. Source:wikimedia commons, Explanation of terms can be found at http://en.wikipedia.org/wiki/Apache_Subversion, &amp;quot;Branching and tagging&amp;quot; and at http://en.wikipedia.org/wiki/Revision_control, #&amp;quot;Common vocabulary&amp;quot;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Features:''' &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Subversion#Features&amp;lt;/ref&amp;gt;&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Commit_(data_management) Commits] as true [http://en.wikipedia.org/wiki/Atomicity_(database_systems) atomic operations] (interrupted commit operations in CVS would cause repository inconsistency or corruption).&lt;br /&gt;
* Renamed/copied/moved/removed files retain full revision history.&lt;br /&gt;
* The system maintains [http://en.wikipedia.org/wiki/Software_versioning versioning] for directories, renames, and file [http://en.wikipedia.org/wiki/Metadata metadata] (but not for timestamps). Users can move and/or copy entire directory-trees very quickly, while retaining full revision history.&lt;br /&gt;
* Versioning of [http://en.wikipedia.org/wiki/Symbolic_link symbolic link]s.&lt;br /&gt;
* Native support for binary files, with space-efficient binary-diff storage.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Apache_HTTP_Server Apache HTTP Server] as network server, [http://en.wikipedia.org/wiki/WebDAV WebDAV]/[http://en.wikipedia.org/wiki/WebDAV#Extensions_and_derivatives Delta-V] for protocol. There is also an independent server [http://en.wikipedia.org/wiki/Process_(computing) process] called svnserve that uses a custom protocol over [http://en.wikipedia.org/wiki/Internet_Protocol_Suite TCP/IP].&lt;br /&gt;
* [[Branching (software)|Branching]] as a cheap operation, independent of file size (though Subversion itself does not distinguish between a branch and a directory)&lt;br /&gt;
* Natively [http://en.wikipedia.org/wiki/Client%E2%80%93server_model client–server], [http://en.wikipedia.org/wiki/Abstraction_layer layered] [http://en.wikipedia.org/wiki/Library_(computing) library] design.&lt;br /&gt;
* Client/server protocol sends [[diff]]s in both directions.&lt;br /&gt;
* Costs proportional to change size, not to data size.&lt;br /&gt;
* [[Parsing|Parsable]] output, including [[XML]] log output.&lt;br /&gt;
* [[Open source]] licensed — [[Apache License]] in the projected 1.7 release; prior versions use a derivative of the Apache Software License, v1.1&lt;br /&gt;
* [[Internationalization and localization|Internationalized]] program messages.&lt;br /&gt;
* [[File locking]] for unmergeable files (&amp;quot;reserved checkouts&amp;quot;).&lt;br /&gt;
* Path-based authorization.&lt;br /&gt;
* [[Language binding]]s for [[C Sharp (programming language)|C#]], [[PHP]], [[Python (programming language)|Python]], [[Perl]], [[Ruby (programming language)|Ruby]], and [[Java (programming language)|Java]].&lt;br /&gt;
* Full [[MIME]] support — users can view or change the MIME type of each file, with the software knowing which MIME types can have their differences from previous versions shown.&lt;br /&gt;
* Merge tracking - Merges between branches will be tracked, this allows automatically merging between branches without telling Subversion what (doesn't) need to be merged.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====Eclipse Subversive - Subversion (SVN) Team Provider&amp;lt;ref&amp;gt;http://www.eclipse.org/subversive/&amp;lt;/ref&amp;gt;=====&lt;br /&gt;
The Subversive project is aimed to integrate the Subversion (SVN) version control system with the Eclipse platform. Using the Subversive plug-in, you can work with projects stored in Subversion repositories directly from the Eclipse workbench in a way similar to work with other Eclipse version control providers, such as CVS and Git.&lt;br /&gt;
&lt;br /&gt;
'''Subversive Features''': Subversive plug-in provides access to Subversion repositories from the Eclipse workbench.&lt;br /&gt;
&lt;br /&gt;
*'''Full-Scale SVN Client'''&lt;br /&gt;
:Subversive is designed to be used as a full-featured SVN client, so you can update, commit, merge changes, work with SVN properties, view change history and perform other operations with SVN directly from the Eclipse environment.&lt;br /&gt;
   	&lt;br /&gt;
*'''Advanced SVN Features'''&lt;br /&gt;
:Subversive includes several features that extend functionality of the standard SVN client. In particular, Subversive can show the SVN repository content grouped by the logical structures of trunk, branch and tag and display changes on a visual revisions graph.&lt;br /&gt;
&lt;br /&gt;
*'''Seamless Integration with Eclipse'''&lt;br /&gt;
:Subversive is an official Eclipse project and an integral part of Eclipse Simultaneous releases. The project follows all Eclipse guidelines and requirements to deliver a quality SVN team provider plug-in similar to CVS and Git implementations.&lt;br /&gt;
   	&lt;br /&gt;
*'''Support of the Latest SVN Versions'''&lt;br /&gt;
:Subversive evolves together with the Subversion project to provide Eclipse users with the features that appeared in new versions of the SVN implementation. You can use the new SVN functionality in Eclipse by installing the Early Access version of Subversive.&lt;br /&gt;
&lt;br /&gt;
===='''Configuration Management Version Control (CMVC)'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/IBM_Configuration_Management_Version_Control_(CMVC)&amp;lt;/ref&amp;gt;==== &lt;br /&gt;
It was developed by IBM Corporation in the mid-late 1990s and was derived in part from software purchased from HP and from IBM's internal-use-only system, IDSS. CMVC was superseded by IBM Rational ClearCase and ClearQuest. The system was used to manage the IBM OS/2 and IBM AIX source code repositories in the 1990s. It is still widely used within IBM by various teams. &lt;br /&gt;
&lt;br /&gt;
One of the drawbacks of CMVC is that, once a file is checked-out by a user, it remains locked to all the other users until the either the new version is checked-in or the lock is released explicitly by the owner (user) of the lock. Some proprietary client-server based version control softwares are:&lt;br /&gt;
::*[http://en.wikipedia.org/wiki/Autodesk_Vault Autodesk Vault] was specifically developed for Autodesk applications.&lt;br /&gt;
::*[http://en.wikipedia.org/wiki/IBM_Rational_ClearCase ClearCase] was developed by IBM Rational Software. It's a Source Code Control (SCC) compliant software.&lt;br /&gt;
::*[http://en.wikipedia.org/wiki/Visual_SourceSafe Visual SourceSafe] is developed by Microsoft targeting small development team.&lt;br /&gt;
::*[http://en.wikipedia.org/wiki/Visual_Studio_Team_System Visual Studio Team System] is also developed by Microsoft targeting larger groups.&lt;br /&gt;
&lt;br /&gt;
===Distributed model===&lt;br /&gt;
'''Distributed Version Control (DVCS)''', or '''Decentralized Version Control''' systems can have many central repositories.This is a peer to peer approach. The concept started developing at late 90's. In DVCS. Each developer works with his or her local repository and the changes are synchronized between repositories upon commit. DVCS are better suited for large teams with partially independent developers. i.e.- opensource software development.[8]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Monotone_%28software%29 Monotone] and [http://en.wikipedia.org/wiki/GNU_arch GNU arch]  were the first generation DVCS (release:2001-2003) followed by [http://en.wikipedia.org/wiki/Darcs Darcs] (stable release:2010).[http://en.wikipedia.org/wiki/Mercurial Mercurial] , [http://en.wikipedia.org/wiki/Git_%28software%29 Git] and [http://en.wikipedia.org/wiki/Bazaar_%28software%29 Bazaar] (2005-2007) are well adopted among developers.   &lt;br /&gt;
#[http://en.wikipedia.org/wiki/BitKeeper BitKeeper],[http://en.wikipedia.org/wiki/Code_Co-op Code Co-op], [http://en.wikipedia.org/wiki/Sun_WorkShop_TeamWare Sun WorkShop TeamWare] are some proprietary DVCS softwares.&lt;br /&gt;
&lt;br /&gt;
It should be noted that many distributed version control softwares support client-server model too.One of the benefits of DVCS is that a developer can save the source code as long as he wants even if the central repository (in client-server model) is discarded at the end of a project.&lt;br /&gt;
&lt;br /&gt;
[[Image:timeline.jpg|650px|thumb|center|A generalized timeline. Source:http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki1a_5_History_of_version_control_by_av]]&lt;br /&gt;
&lt;br /&gt;
== File Sharing Models ==&lt;br /&gt;
Every system that implement version controlling have to address one fundamental problem: How will the files in the repository be safely shared across users but prevent them from accidentally stepping on each other's feet? It's all too easy for users to accidentally overwrite each other's changes in the repository.&lt;br /&gt;
&lt;br /&gt;
Consider the scenario with two users A and B. Both of them check out the same file (same version). User A after making his modification, suppose, commits the file first. A few moments later B completes his modification. B does not have any clue about A's check-in and he happily commits his code to the repository. Now B has accidentally overwritten the changes made by A leaving the system in an inconsistent state. This problem can be solved in two different ways:&amp;lt;br/&amp;gt;&lt;br /&gt;
* Lock-Modify-Unlock&lt;br /&gt;
* Copy-Modify-Merge &amp;lt;br/&amp;gt;&lt;br /&gt;
While CMVC follows the lock-modify-unlock solution, svn follows copy-modify-merge allowing users to modify the same piece of code concurrently. &amp;lt;br/&amp;gt;&lt;br /&gt;
The problem with the lock-modify-unlock model is that it's a bit restrictive and often becomes a roadblock for users:&lt;br /&gt;
&lt;br /&gt;
* Locking may cause unnecessary delay and is not desired when it comes to teams/projects which have a small cycle time between releases. For example: Suppose say, user A checks out a file (locks it) and some interrupt in his work causes him to switch to another task of higher priority. There is a possibility that he forgets completely about the file that he checked out. Now, if another user B wants to edit the same file, he cannot do so, without having the administrator unlock the file for him, his hands are tied!&lt;br /&gt;
&lt;br /&gt;
* Locking may cause unnecessary serialization: What if two different users A and B want to edit different non-intersecting portions of the same file? With proper merging solution in place, they could have done it easily without bothering about what the other user does with the file.&lt;br /&gt;
&lt;br /&gt;
* Locking may create a false sense of security: As with any model, lock-modify-unlock approach too allows two different users to work on separate files simultaneously. However the model does not define how dependencies between files are dealt with.&amp;lt;br/&amp;gt;For example: Suppose A locks and edits file f1, while B simultaneously locks and edits file f2. If there is a function call in f1 whose definition exists in f2 but the definition is removed or the function name is changed after editing f2, they don't work together anymore.&amp;lt;br/&amp;gt;Thus, locking files by itself does not provide security against such deliberate changes. Lot of manual synchronization is needed to avoid such situations which is only going to cause delay in the development of the project.&lt;br /&gt;
&lt;br /&gt;
==Use of version control in other areas ==&lt;br /&gt;
&lt;br /&gt;
Now a days, many document editing softwares have adopted version control. Wikis, GoogleDoc, Microsoft Office and OpenOffice.org suite are some example softwares that can save previous document editing history. &lt;br /&gt;
&lt;br /&gt;
==Other considerations==&lt;br /&gt;
&lt;br /&gt;
Most open source softwares have [http://linuxmafia.com/faq/Apps/vcs.html distributions for Linux] OS. In most open source cases, Linux and windows versions are released concurrently. &lt;br /&gt;
Many VCS' have plugins for common IDEs like Eclipse, Visual Studio, Oracle JDeveloper etc. NetBeans IDE and Xcode has integrated version control support.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Additional References==&lt;br /&gt;
&lt;br /&gt;
1. [http://subversion.apache.org/news.html#news-20100217.  Apache Software Foundation Announcements, &amp;quot;Subversion becomes Apache Subversion&amp;quot;.(2010-02-17) Accessed:September 2010 ]&lt;br /&gt;
&lt;br /&gt;
2. [http://svnbook.red-bean.com/ Ben Collins-Sussman, Brian W. Fitzpatrick, C. Michael Pilato. &amp;quot;Version Control with Subversion&amp;quot;, an O'Reilly book available online. Accessed:September 2010] &lt;br /&gt;
&lt;br /&gt;
3. [http://shop.oreilly.com/product/9781565921177.do Don Bolinger, Tan Bronson: Applying RCS and SCCS. O'Reilly Media. ISBN:978-1-56592-117-7]  &lt;br /&gt;
&lt;br /&gt;
4. [http://www.ericsink.com/scm/source_control.html  Eric Sink: A collection of articles on source control and best practices, Accessed:September 2010]&lt;br /&gt;
&lt;br /&gt;
5. [http://basepath.com/aup/talks/SCCS-Slideshow.pdf  M. J. Rochkind: The Source Code Control System.] In IEEE Transactions on Software Engineering SE-1:4 (Dec. 1975), pages 364–370.&lt;br /&gt;
&lt;br /&gt;
6. [http://onlinelibrary.wiley.com/doi/10.1002/bltj.2039/pdf Martin, Robert L. (2002). &amp;quot;Software configuration management for the 21st century&amp;quot;. Bell Labs technical journal, Volume 2, Issue 1, page- 154.]&lt;br /&gt;
&lt;br /&gt;
7. Mike Mason; Pragmatic Version Control Using Subversion; Pragmatic Bookshelf; ISBN 0-9745140-6-3 (1st edition, paperback, 2005)&lt;br /&gt;
&lt;br /&gt;
8. [http://www.ibm.com/developerworks/aix/library/au-dist_ver_control/ Noah Gift,Adam Shand: Introduction to distributed version control systems (compare how to use Bazaar, Mercurial, and Git) (Apr 2009), IBM Technical Library, Accessed:September 2010 ] &lt;br /&gt;
&lt;br /&gt;
9.[http://onlinelibrary.wiley.com/doi/10.1002/spe.4380150703/abstract Walter F. Tichy; Rcs - a system for version control; In Software: Practice and Experience. Volume 15, Issue 7,(July 1985) pages 637–654 ]&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Revision_control Wikipedia: Revision control]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/List_of_revision_control_software Wikipedia: List of revision control software]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Comparison_of_revision_control_software Wikipedia: Detail comparison of revision control softwares]&lt;br /&gt;
&lt;br /&gt;
[http://www.nongnu.org/cvs/ CVS webpage]&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.vu.nl/~dick/  Dick Grune's website on CVS history]&lt;br /&gt;
&lt;br /&gt;
[http://groups.google.com/group/mod.sources/msg/2ebab72ac0744fb8?dmode=source The original usenet post on CVS] archived at google groups.&lt;br /&gt;
&lt;br /&gt;
[http://linuxmafia.com/faq/Apps/vcs.html Linux availability of various version control softwares]&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w1_rk&amp;diff=62937</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w1 rk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w1_rk&amp;diff=62937"/>
		<updated>2012-09-07T23:43:10Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* File Sharing Models */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Revision_control version control] system '''(VCS)''' is a process for managing software codes,files and directory structures and corresponding updates made to them during software development, web development etc. project or during subsequent project maintenances. Version control is also known as revision control, source control or [http://en.wikipedia.org/wiki/Software_configuration_management software configuration management] (SCM)[6].&lt;br /&gt;
&lt;br /&gt;
Any software development project is a dynamic and fast paced environment. In a typical setting, development for a project is performed simultaneously by many developers. Thus, incorporating all the changes made, either simultaneously or at different times, poses a new type of challenge. &lt;br /&gt;
&lt;br /&gt;
This wikibook chapter focuses mainly on the development history of different version control systems.&lt;br /&gt;
&lt;br /&gt;
==Why version control systems are needed?==&lt;br /&gt;
The major issues in a dynamic development environment can be described as:&lt;br /&gt;
* Obviously, '''merging''' of a lot of files. If we consider somebody to do merging manually, The sheer volume of communication required is overwhelming. This communication can be among the developers themselves in a small team or between the team leader in charge of merging and the rest of the group.&lt;br /&gt;
&lt;br /&gt;
* '''Accountability:''' if one of the developers breaks the code flow during development, It is tough to detect and naturally nobody steps forward to take the blame. A version control system can precisely indicate who caused the break in the code.&lt;br /&gt;
&lt;br /&gt;
* If a certain code implementation doesn't work as expected, '''Reverting''' to last satisfactory state may be required. &lt;br /&gt;
&lt;br /&gt;
* Development on stale code may result in '''Code loss'''. for example, two developers downloaded a certain file at 10AM. One of the developers modified foo_1() method and uploaded modified file at 10:30AM.The other developer modified foo_2() method and uploaded the same file at 10:45AM. Since the functions are in the same file, the second upload will overwrite the file uploaded by first developer at 10:30AM causing loss of his part of work.    &lt;br /&gt;
&lt;br /&gt;
* Even a lone coder might need to '''review''' why he or she made a certain change in code. Comments during code check-in can be a useful resource in such situation. &lt;br /&gt;
&lt;br /&gt;
* Version control provides a form of '''documentation''' which makes tracking easy. i.e.-'''tagging''' is a kind of snapshot of all files and documents at a particular stage of development, usually during a stable release. This allows the developers to work with the exact files that were included in that release for bug-fixing purpose. &lt;br /&gt;
&lt;br /&gt;
* '''Sandboxing / Branching:''' Version control makes it possible to perform temporary code changes in an isolated area, usually in branch folder, for testing purpose. If the outcome is satisfactory then the code can be merged with the existing code, otherwise it can be discarded without having any impact on the main code.&lt;br /&gt;
&lt;br /&gt;
* Now a days, software development teams are spread across different countries and work at different time zones. Use of a version control system for project aggregation becomes unavoidable.&lt;br /&gt;
 &lt;br /&gt;
==Evolution of version control systems==&lt;br /&gt;
&lt;br /&gt;
VCS' can be broadly categorized into three groups based on the repository model. The sequence below follows the evolution of version control systems as well: &lt;br /&gt;
&lt;br /&gt;
==='''Local repository model''' &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Source_Code_Control_System&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Local version control systems had one storage location of the files. It was called local because it didn't support networked commands or access like the other later softwares. So, all the developers had to use same computer system to access or modify files.  &lt;br /&gt;
&lt;br /&gt;
===='''Source Code Control System (SCCS)'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Source_Code_Control_System&amp;lt;/ref&amp;gt;==== &lt;br /&gt;
It is one of the pioneer source code revision softwares.[5] SCCS was developed at Bell Labs in 1972 by Marc J. Rochkind. Although it was originally developed for OS/MVT, SCCS was included in [http://en.wikipedia.org/wiki/Source_Code_Control_System some UNIX distributions.] SCCS ruled as the dominant VCS until ''Revision Control System'' was released.&lt;br /&gt;
:SCCS was the dominant version control system for Unix until the release of the [http://en.wikipedia.org/wiki/Revision_Control_System Revision Control System (RCS)]. Today, SCCS is generally considered obsolete. However, its file format is still used internally by a few other revision control programs, including [http://en.wikipedia.org/wiki/BitKeeper BitKeeper] and [http://en.wikipedia.org/wiki/TeamWare TeamWare]. The latter is a frontend to SCCS. [http://en.wikipedia.org/wiki/Sablime Sablime] has been developed from a modified version of SCCS but uses a history file format that is incompatible with SCCS. The SCCS file format uses a storage technique called [http://en.wikipedia.org/wiki/Interleaved_deltas interleaved deltas] (or the weave). This storage technique is now considered by many [http://en.wikipedia.org/wiki/Revision_control revision control] system developers as foundational to advanced merging and versioning techniques, such as the &amp;quot;Precise [http://en.wikipedia.org/wiki/Codeville Codeville]&amp;quot; (&amp;quot;pcdv&amp;quot;) merge.&lt;br /&gt;
:'''What does a source code control system do?'''&lt;br /&gt;
:If you are creating or maintaining a text file---perhaps a document, or a script, or a program---a source code control system can do several things for you:&lt;br /&gt;
:*It can keep track of the changes made to the file: what was changed, when it was changed, and by whom.&lt;br /&gt;
:*It provides a version numbering scheme so you can tell which versions of a file are more recent.&lt;br /&gt;
:*It can retrieve previous versions of your file, so that you can retreat to an older version if you decide that the current version is a bad idea, or if you want to see some text that has since been changed or deleted.&lt;br /&gt;
:*If you accidentally delete the current file, you can get back the last version.&lt;br /&gt;
:*If several people are working with the same file, a source code control system can help you coordinate your work and keep track of who did what, and when.&lt;br /&gt;
&lt;br /&gt;
SCCS is also known for the &amp;lt;code&amp;gt;sccsid&amp;lt;/code&amp;gt; string, for example:&lt;br /&gt;
&lt;br /&gt;
 static char sccsid[] = &amp;quot;@(#)ls.c        8.1 (Berkeley) 6/11/93&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
This string contains the file name, date, and can also contain a comment. After compilation, this string can be found in binary and object files by looking for the pattern &amp;quot;@(#)&amp;quot; and can be used determine which source code files were used during compilation.&lt;br /&gt;
&lt;br /&gt;
===='''Control System(RCS)'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Revision_Control_System Revision&amp;lt;/ref&amp;gt;==== &lt;br /&gt;
It automated storing, retrieval, logging, identification, and merging frequent revisions of texts. RCS was first released in 1982 by Walter F. Tichy as an alternative to SCCS. It quickly gained popularity and almost replaced SCCS.[9] &lt;br /&gt;
:RCS performed better by storing the most recent copy of file and then storing only reverse differences called &amp;quot;deltas&amp;quot;.One of the shortcomings of RCS was that only one person at a time could edit the file. RCS could manage only single files, not a whole project or directory.&lt;br /&gt;
:Ref.[3] is a comprehensive book on CSSC and RCS.&lt;br /&gt;
&lt;br /&gt;
==='''Client-server model'''===&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Client%E2%80%93server_model client-server model] utilizes a single centralized repository for the version control which is accessible to the developers through network or internet. The below diagram [http://svnbook.red-bean.com/en/1.7/svn.basic.version-control-basics.html] provides a high level overview of the model.&lt;br /&gt;
[[Image:Client_Server_Model.png |center|]]&lt;br /&gt;
===='''Concurrent Versions System (CVS)'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Concurrent_Versions_System&amp;lt;/ref&amp;gt;====&lt;br /&gt;
It was one of the early client-server model based scheme. Dick Grune started developing CVS from 1984-1985 to allow his students to collaborate in a project according to their schedule. CVS was publicly released at 1986.The main improvement for CVS over RCS was that CVS could manage the whole project while RCS could only work on a file at a time.At the beginning, CVS was script based and called RCS at background. Later it was developed into a full fledged program. A lot of the IDE's (Emacs, Eclipse/aptana,Netbeans, Komodo, PHPEdit etc.) support CVS. CVSNT is a cross platform port of CVS with some modification. CVS, which was the defacto standard for version controlling for a long time is almost replaced today by SVN. There were many disadvantages of CVS which hindered its stay in the industry further. Prominent ones were&lt;br /&gt;
#CVS check-in is not an [http://en.wikipedia.org/wiki/Atomic_commit atomic] operation. For example, given the files 1.c, 2.c, 3.c, 4.c and if someone runs '''cvs ci 1.c 3.c''' and someone else runs cvs update at the same time, the person running update might get only the change to `3.c' and not the change to `1.c'. So, if check-in process was disturbed, it could result in damage of existing project at repository.&lt;br /&gt;
#CVS only tracks modification on a file-by-file basis. Not scalable for larger projects.&lt;br /&gt;
#CVS was designed with only text files in mind. No native support for other formats. Extensive modification are necessary at the client and the server to support other file types.&lt;br /&gt;
#Conflict resolution in CVS, if not absent, is definitely not good. Conflict markers used in CVS may go unnoticed and those file might find their way into the repository.&lt;br /&gt;
#Slow&lt;br /&gt;
&lt;br /&gt;
===='''Subversion (SVN)'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Subversion_%28software%29&amp;lt;/ref&amp;gt;==== &lt;br /&gt;
As the complexity of projects increased, the shortcomings of CVS became more and more prominent. This led to the development of Subversion. CollabNet started developing svn as a successor of CVS with added [http://en.wikipedia.org/wiki/Subversion_(software)#Features functionality][2][7]. Different open source projects (i.e.-[http://en.wikipedia.org/wiki/Apache_Software_Foundation Apache Software  Foundation],[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby],[http://en.wikipedia.org/wiki/SourceForge SourceForge],[http://en.wikipedia.org/wiki/Tigris.org Tigris.org], [http://en.wikipedia.org/wiki/PHP PHP],  [http://en.wikipedia.org/wiki/Python_(programming_language) Python] and [http://en.wikipedia.org/wiki/MediaWiki MediaWiki]) use Subversion. Subversion is an open source software due to it's Apache license[1].&lt;br /&gt;
[[Image:Subversion_project_visualization.svg.png|650px|thumb|center|Visualization of a very simple Subversion project. Source:wikimedia commons, Explanation of terms can be found at http://en.wikipedia.org/wiki/Apache_Subversion, &amp;quot;Branching and tagging&amp;quot; and at http://en.wikipedia.org/wiki/Revision_control, #&amp;quot;Common vocabulary&amp;quot;]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Features:''' &amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Apache_Subversion#Features&amp;lt;/ref&amp;gt;&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Commit_(data_management) Commits] as true [http://en.wikipedia.org/wiki/Atomicity_(database_systems) atomic operations] (interrupted commit operations in CVS would cause repository inconsistency or corruption).&lt;br /&gt;
* Renamed/copied/moved/removed files retain full revision history.&lt;br /&gt;
* The system maintains [http://en.wikipedia.org/wiki/Software_versioning versioning] for directories, renames, and file [http://en.wikipedia.org/wiki/Metadata metadata] (but not for timestamps). Users can move and/or copy entire directory-trees very quickly, while retaining full revision history.&lt;br /&gt;
* Versioning of [http://en.wikipedia.org/wiki/Symbolic_link symbolic link]s.&lt;br /&gt;
* Native support for binary files, with space-efficient binary-diff storage.&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Apache_HTTP_Server Apache HTTP Server] as network server, [http://en.wikipedia.org/wiki/WebDAV WebDAV]/[http://en.wikipedia.org/wiki/WebDAV#Extensions_and_derivatives Delta-V] for protocol. There is also an independent server [http://en.wikipedia.org/wiki/Process_(computing) process] called svnserve that uses a custom protocol over [http://en.wikipedia.org/wiki/Internet_Protocol_Suite TCP/IP].&lt;br /&gt;
* [[Branching (software)|Branching]] as a cheap operation, independent of file size (though Subversion itself does not distinguish between a branch and a directory)&lt;br /&gt;
* Natively [http://en.wikipedia.org/wiki/Client%E2%80%93server_model client–server], [http://en.wikipedia.org/wiki/Abstraction_layer layered] [http://en.wikipedia.org/wiki/Library_(computing) library] design.&lt;br /&gt;
* Client/server protocol sends [[diff]]s in both directions.&lt;br /&gt;
* Costs proportional to change size, not to data size.&lt;br /&gt;
* [[Parsing|Parsable]] output, including [[XML]] log output.&lt;br /&gt;
* [[Open source]] licensed — [[Apache License]] in the projected 1.7 release; prior versions use a derivative of the Apache Software License, v1.1&lt;br /&gt;
* [[Internationalization and localization|Internationalized]] program messages.&lt;br /&gt;
* [[File locking]] for unmergeable files (&amp;quot;reserved checkouts&amp;quot;).&lt;br /&gt;
* Path-based authorization.&lt;br /&gt;
* [[Language binding]]s for [[C Sharp (programming language)|C#]], [[PHP]], [[Python (programming language)|Python]], [[Perl]], [[Ruby (programming language)|Ruby]], and [[Java (programming language)|Java]].&lt;br /&gt;
* Full [[MIME]] support — users can view or change the MIME type of each file, with the software knowing which MIME types can have their differences from previous versions shown.&lt;br /&gt;
* Merge tracking - Merges between branches will be tracked, this allows automatically merging between branches without telling Subversion what (doesn't) need to be merged.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====Eclipse Subversive - Subversion (SVN) Team Provider&amp;lt;ref&amp;gt;http://www.eclipse.org/subversive/&amp;lt;/ref&amp;gt;=====&lt;br /&gt;
The Subversive project is aimed to integrate the Subversion (SVN) version control system with the Eclipse platform. Using the Subversive plug-in, you can work with projects stored in Subversion repositories directly from the Eclipse workbench in a way similar to work with other Eclipse version control providers, such as CVS and Git.&lt;br /&gt;
&lt;br /&gt;
'''Subversive Features''': Subversive plug-in provides access to Subversion repositories from the Eclipse workbench.&lt;br /&gt;
&lt;br /&gt;
*'''Full-Scale SVN Client'''&lt;br /&gt;
:Subversive is designed to be used as a full-featured SVN client, so you can update, commit, merge changes, work with SVN properties, view change history and perform other operations with SVN directly from the Eclipse environment.&lt;br /&gt;
   	&lt;br /&gt;
*'''Advanced SVN Features'''&lt;br /&gt;
:Subversive includes several features that extend functionality of the standard SVN client. In particular, Subversive can show the SVN repository content grouped by the logical structures of trunk, branch and tag and display changes on a visual revisions graph.&lt;br /&gt;
&lt;br /&gt;
*'''Seamless Integration with Eclipse'''&lt;br /&gt;
:Subversive is an official Eclipse project and an integral part of Eclipse Simultaneous releases. The project follows all Eclipse guidelines and requirements to deliver a quality SVN team provider plug-in similar to CVS and Git implementations.&lt;br /&gt;
   	&lt;br /&gt;
*'''Support of the Latest SVN Versions'''&lt;br /&gt;
:Subversive evolves together with the Subversion project to provide Eclipse users with the features that appeared in new versions of the SVN implementation. You can use the new SVN functionality in Eclipse by installing the Early Access version of Subversive.&lt;br /&gt;
&lt;br /&gt;
===='''Configuration Management Version Control (CMVC)'''&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/IBM_Configuration_Management_Version_Control_(CMVC)&amp;lt;/ref&amp;gt;==== &lt;br /&gt;
It was developed by IBM Corporation in the mid-late 1990s and was derived in part from software purchased from HP and from IBM's internal-use-only system, IDSS. CMVC was superseded by IBM Rational ClearCase and ClearQuest. The system was used to manage the IBM OS/2 and IBM AIX source code repositories in the 1990s. It is still widely used within IBM by various teams. &lt;br /&gt;
&lt;br /&gt;
::One of the drawbacks of CMVC is that, once a file is checked-out by a user, it remains locked to all the other users until the either the new version is checked-in or the lock is released explicitly by the owner (user) of the lock. Some proprietary client-server based version control softwares are:&lt;br /&gt;
::*[http://en.wikipedia.org/wiki/Autodesk_Vault Autodesk Vault] was specifically developed for Autodesk applications.&lt;br /&gt;
::*[http://en.wikipedia.org/wiki/IBM_Rational_ClearCase ClearCase] was developed by IBM Rational Software. It's a Source Code Control (SCC) compliant software.&lt;br /&gt;
::*[http://en.wikipedia.org/wiki/Visual_SourceSafe Visual SourceSafe] is developed by Microsoft targeting small development team.&lt;br /&gt;
::*[http://en.wikipedia.org/wiki/Visual_Studio_Team_System Visual Studio Team System] is also developed by Microsoft targeting larger groups.&lt;br /&gt;
&lt;br /&gt;
===Distributed model===&lt;br /&gt;
'''Distributed Version Control (DVCS)''', or '''Decentralized Version Control''' systems can have many central repositories.This is a peer to peer approach. The concept started developing at late 90's. In DVCS. Each developer works with his or her local repository and the changes are synchronized between repositories upon commit. DVCS are better suited for large teams with partially independent developers. i.e.- opensource software development.[8]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Monotone_%28software%29 Monotone] and [http://en.wikipedia.org/wiki/GNU_arch GNU arch]  were the first generation DVCS (release:2001-2003) followed by [http://en.wikipedia.org/wiki/Darcs Darcs] (stable release:2010).[http://en.wikipedia.org/wiki/Mercurial Mercurial] , [http://en.wikipedia.org/wiki/Git_%28software%29 Git] and [http://en.wikipedia.org/wiki/Bazaar_%28software%29 Bazaar] (2005-2007) are well adopted among developers.   &lt;br /&gt;
#[http://en.wikipedia.org/wiki/BitKeeper BitKeeper],[http://en.wikipedia.org/wiki/Code_Co-op Code Co-op], [http://en.wikipedia.org/wiki/Sun_WorkShop_TeamWare Sun WorkShop TeamWare] are some proprietary DVCS softwares.&lt;br /&gt;
&lt;br /&gt;
It should be noted that many distributed version control softwares support client-server model too.One of the benefits of DVCS is that a developer can save the source code as long as he wants even if the central repository (in client-server model) is discarded at the end of a project.&lt;br /&gt;
&lt;br /&gt;
[[Image:timeline.jpg|650px|thumb|center|A generalized timeline. Source:http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki1a_5_History_of_version_control_by_av]]&lt;br /&gt;
&lt;br /&gt;
== File Sharing Models ==&lt;br /&gt;
Every system that implement version controlling have to address one fundamental problem: How will the files in the repository be safely shared across users but prevent them from accidentally stepping on each other's feet? It's all too easy for users to accidentally overwrite each other's changes in the repository.&lt;br /&gt;
&lt;br /&gt;
Consider the scenario with two users A and B. Both of them check out the same file (same version). User A after making his modification, suppose, commits the file first. A few moments later B completes his modification. B does not have any clue about A's check-in and he happily commits his code to the repository. Now B has accidentally overwritten the changes made by A leaving the system in an inconsistent state. This problem can be solved in two different ways:&amp;lt;br/&amp;gt;&lt;br /&gt;
* Lock-Modify-Unlock&lt;br /&gt;
* Copy-Modify-Merge &amp;lt;br/&amp;gt;&lt;br /&gt;
While CMVC follows the lock-modify-unlock solution, svn follows copy-modify-merge allowing users to modify the same piece of code concurrently. &amp;lt;br/&amp;gt;&lt;br /&gt;
The problem with the lock-modify-unlock model is that it's a bit restrictive and often becomes a roadblock for users:&lt;br /&gt;
&lt;br /&gt;
* Locking may cause unnecessary delay and is not desired when it comes to teams/projects which have a small cycle time between releases. For example: Suppose say, user A checks out a file (locks it) and some interrupt in his work causes him to switch to another task of higher priority. There is a possibility that he forgets completely about the file that he checked out. Now, if another user B wants to edit the same file, he cannot do so, without having the administrator unlock the file for him, his hands are tied!&lt;br /&gt;
&lt;br /&gt;
* Locking may cause unnecessary serialization: What if two different users A and B want to edit different non-intersecting portions of the same file? With proper merging solution in place, they could have done it easily without bothering about what the other user does with the file.&lt;br /&gt;
&lt;br /&gt;
* Locking may create a false sense of security: As with any model, lock-modify-unlock approach too allows two different users to work on separate files simultaneously. However the model does not define how dependencies between files are dealt with.&amp;lt;br/&amp;gt;For example: Suppose A locks and edits file f1, while B simultaneously locks and edits file f2. If there is a function call in f1 whose definition exists in f2 but the definition is removed or the function name is changed after editing f2, they don't work together anymore.&amp;lt;br/&amp;gt;Thus, locking files by itself does not provide security against such deliberate changes. Lot of manual synchronization is needed to avoid such situations which is only going to cause delay in the development of the project.&lt;br /&gt;
&lt;br /&gt;
==Use of version control in other areas ==&lt;br /&gt;
&lt;br /&gt;
Now a days, many document editing softwares have adopted version control. Wikis, GoogleDoc, Microsoft Office and OpenOffice.org suite are some example softwares that can save previous document editing history. &lt;br /&gt;
&lt;br /&gt;
==Other considerations==&lt;br /&gt;
&lt;br /&gt;
Most open source softwares have [http://linuxmafia.com/faq/Apps/vcs.html distributions for Linux] OS. In most open source cases, Linux and windows versions are released concurrently. &lt;br /&gt;
Many VCS' have plugins for common IDEs like Eclipse, Visual Studio, Oracle JDeveloper etc. NetBeans IDE and Xcode has integrated version control support.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Additional References==&lt;br /&gt;
&lt;br /&gt;
1. [http://subversion.apache.org/news.html#news-20100217.  Apache Software Foundation Announcements, &amp;quot;Subversion becomes Apache Subversion&amp;quot;.(2010-02-17) Accessed:September 2010 ]&lt;br /&gt;
&lt;br /&gt;
2. [http://svnbook.red-bean.com/ Ben Collins-Sussman, Brian W. Fitzpatrick, C. Michael Pilato. &amp;quot;Version Control with Subversion&amp;quot;, an O'Reilly book available online. Accessed:September 2010] &lt;br /&gt;
&lt;br /&gt;
3. [http://shop.oreilly.com/product/9781565921177.do Don Bolinger, Tan Bronson: Applying RCS and SCCS. O'Reilly Media. ISBN:978-1-56592-117-7]  &lt;br /&gt;
&lt;br /&gt;
4. [http://www.ericsink.com/scm/source_control.html  Eric Sink: A collection of articles on source control and best practices, Accessed:September 2010]&lt;br /&gt;
&lt;br /&gt;
5. [http://basepath.com/aup/talks/SCCS-Slideshow.pdf  M. J. Rochkind: The Source Code Control System.] In IEEE Transactions on Software Engineering SE-1:4 (Dec. 1975), pages 364–370.&lt;br /&gt;
&lt;br /&gt;
6. [http://onlinelibrary.wiley.com/doi/10.1002/bltj.2039/pdf Martin, Robert L. (2002). &amp;quot;Software configuration management for the 21st century&amp;quot;. Bell Labs technical journal, Volume 2, Issue 1, page- 154.]&lt;br /&gt;
&lt;br /&gt;
7. Mike Mason; Pragmatic Version Control Using Subversion; Pragmatic Bookshelf; ISBN 0-9745140-6-3 (1st edition, paperback, 2005)&lt;br /&gt;
&lt;br /&gt;
8. [http://www.ibm.com/developerworks/aix/library/au-dist_ver_control/ Noah Gift,Adam Shand: Introduction to distributed version control systems (compare how to use Bazaar, Mercurial, and Git) (Apr 2009), IBM Technical Library, Accessed:September 2010 ] &lt;br /&gt;
&lt;br /&gt;
9.[http://onlinelibrary.wiley.com/doi/10.1002/spe.4380150703/abstract Walter F. Tichy; Rcs - a system for version control; In Software: Practice and Experience. Volume 15, Issue 7,(July 1985) pages 637–654 ]&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Revision_control Wikipedia: Revision control]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/List_of_revision_control_software Wikipedia: List of revision control software]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Comparison_of_revision_control_software Wikipedia: Detail comparison of revision control softwares]&lt;br /&gt;
&lt;br /&gt;
[http://www.nongnu.org/cvs/ CVS webpage]&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.vu.nl/~dick/  Dick Grune's website on CVS history]&lt;br /&gt;
&lt;br /&gt;
[http://groups.google.com/group/mod.sources/msg/2ebab72ac0744fb8?dmode=source The original usenet post on CVS] archived at google groups.&lt;br /&gt;
&lt;br /&gt;
[http://linuxmafia.com/faq/Apps/vcs.html Linux availability of various version control softwares]&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w1_rk&amp;diff=62884</id>
		<title>CSC/ECE 517 Fall 2012/ch1 1w1 rk</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1_1w1_rk&amp;diff=62884"/>
		<updated>2012-09-07T04:21:56Z</updated>

		<summary type="html">&lt;p&gt;Karthi2: /* File Sharing Models */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
A [http://en.wikipedia.org/wiki/Revision_control version control] system '''(VCS)''' is a process for managing software codes,files and directory structures and corresponding updates made to them during software development, web development etc. project or during subsequent project maintenances. Version control is also known as revision control, source control or [http://en.wikipedia.org/wiki/Software_configuration_management software configuration management] (SCM)[6].&lt;br /&gt;
&lt;br /&gt;
Any software development project is a dynamic and fast paced environment. In a typical setting, development for a project is performed simultaneously by many developers. Thus, incorporating all the changes made, either simultaneously or at different times, poses a new type of challenge. &lt;br /&gt;
&lt;br /&gt;
This wikibook chapter focuses mainly on the development history of different version control systems.&lt;br /&gt;
&lt;br /&gt;
==Why version control systems are needed?==&lt;br /&gt;
The major issues in a dynamic development environment can be described as:&lt;br /&gt;
* Obviously, '''merging''' of a lot of files. If we consider somebody to do merging manually, The sheer volume of communication required is overwhelming. This communication can be among the developers themselves in a small team or between the team leader in charge of merging and the rest of the group.&lt;br /&gt;
&lt;br /&gt;
* '''Accountability:''' if one of the developers breaks the code flow during development, It is tough to detect and naturally nobody steps forward to take the blame. A version control system can precisely indicate who caused the break in the code.&lt;br /&gt;
&lt;br /&gt;
* If a certain code implementation doesn't work as expected, '''Reverting''' to last satisfactory state may be required. &lt;br /&gt;
&lt;br /&gt;
* Development on stale code may result in '''Code loss'''. for example, two developers downloaded a certain file at 10AM. One of the developers modified foo_1() method and uploaded modified file at 10:30AM.The other developer modified foo_2() method and uploaded the same file at 10:45AM. Since the functions are in the same file, the second upload will overwrite the file uploaded by first developer at 10:30AM causing loss of his part of work.    &lt;br /&gt;
&lt;br /&gt;
* Even a lone coder might need to '''review''' why he or she made a certain change in code. Comments during code check-in can be a useful resource in such situation. &lt;br /&gt;
&lt;br /&gt;
* Version control provides a form of '''documentation''' which makes tracking easy. i.e.-'''tagging''' is a kind of snapshot of all files and documents at a particular stage of development, usually during a stable release. This allows the developers to work with the exact files that were included in that release for bug-fixing purpose. &lt;br /&gt;
&lt;br /&gt;
* '''Sandboxing / Branching:''' Version control makes it possible to perform temporary code changes in an isolated area, usually in branch folder, for testing purpose. If the outcome is satisfactory then the code can be merged with the existing code, otherwise it can be discarded without having any impact on the main code.&lt;br /&gt;
&lt;br /&gt;
* Now a days, software development teams are spread across different countries and work at different time zones. Use of a version control system for project aggregation becomes unavoidable.&lt;br /&gt;
 &lt;br /&gt;
==Evolution of version control systems==&lt;br /&gt;
&lt;br /&gt;
VCS' can be broadly categorized into three groups based on the repository model. The sequence below follows the evolution of version control systems as well: &lt;br /&gt;
&lt;br /&gt;
==='''Local repository model'''===&lt;br /&gt;
Local version control systems had one storage location of the files. It was called local because it didn't support networked commands or access like the other later softwares. So, all the developers had to use same computer system to access or modify files.  &lt;br /&gt;
#'''[http://en.wikipedia.org/wiki/Source_Code_Control_System Source Code Control System (SCCS)]''' is one of the pioneer source code revision softwares.[5] SCCS was developed at Bell Labs in 1972 by Marc J. Rochkind. Although it was originally developed for OS/MVT, SCCS was included in [http://en.wikipedia.org/wiki/Source_Code_Control_System some UNIX distributions.] SCCS ruled as the dominant VCS until ''Revision Control System'' was released.&lt;br /&gt;
#'''[http://en.wikipedia.org/wiki/Revision_Control_System Revision Control System(RCS)]''' automated storing, retrieval, logging, identification, and merging frequent revisions of texts. RCS was first released in 1982 by Walter F. Tichy as an alternative to SCCS. It quickly gained popularity and almost replaced SCCS.[9] &lt;br /&gt;
::RCS performed better by storing the most recent copy of file and then storing only reverse differences called &amp;quot;deltas&amp;quot;.One of the shortcomings of RCS was that only one person at a time could edit the file. RCS could manage only single files, not a whole project or directory.&lt;br /&gt;
::Ref.[3] is a comprehensive book on CSSC and RCS.&lt;br /&gt;
==='''Client-server model'''===&lt;br /&gt;
The [http://en.wikipedia.org/wiki/Client%E2%80%93server_model client-server model] utilizes a single centralized repository for the version control which is accessible to the developers through network or internet. The below diagram&amp;lt;ref&amp;gt;http://svnbook.red-bean.com/en/1.7/svn.basic.version-control-basics.html &amp;lt;/ref&amp;gt; provides a high level overview of the model.&lt;br /&gt;
[[Image:Client_Server_Model.png |center|]]&lt;br /&gt;
&lt;br /&gt;
#'''[http://en.wikipedia.org/wiki/Concurrent_Versions_System Concurrent Versions System (CVS)]''' was one of the early client-server model based scheme. Dick Grune started developing CVS from 1984-1985 to allow his students to collaborate in a project according to their schedule. CVS was publicly released at 1986.The main improvement for CVS over RCS was that CVS could manage the whole project while RCS could only work on a file at a time.At the beginning, CVS was script based and called RCS at background. Later it was developed into a full fledged program. A lot of the IDE's (Emacs, Eclipse/aptana,Netbeans, Komodo, PHPEdit etc.) support CVS. CVSNT is a cross platform port of CVS with some modification. &lt;br /&gt;
::CVS, which was the defacto standard for version controlling for a long time is almost replaced today by SVN. There were many disadvantages of CVS which hindered its stay in the industry further. Prominent ones were&lt;br /&gt;
::*CVS check-in is not an [http://en.wikipedia.org/wiki/Atomic_commit atomic] operation. For example, given the files 1.c, 2.c, 3.c, 4.c and if someone runs &amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; cvs ci 1.c 3.c &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;and someone else runs cvs update at the same time, the person running update might get only the change to `3.c' and not the change to `1.c'. So, if check-in process was disturbed, it &amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;could result in damage of existing project at repository.&lt;br /&gt;
::* CVS only tracks modification on a file-by-file basis. Not scalable for larger projects.&lt;br /&gt;
::* CVS was designed with only text files in mind. No native support for other formats. Extensive modification are necessary at the client and the server to support other file types.&lt;br /&gt;
::* Conflict resolution in CVS, if not absent, is definitely not good. Conflict markers used in CVS may go unnoticed and those file might find their way into the repository.&lt;br /&gt;
::* Slow&lt;br /&gt;
#'''[http://en.wikipedia.org/wiki/Subversion_%28software%29 Subversion (SVN)]''': As the complexity of projects increased, the shortcomings of CVS became more and more prominent. This led to the development of Subversion. CollabNet started developing svn as a successor of CVS with added [http://en.wikipedia.org/wiki/Subversion_(software)#Features functionality][2][7]. Different open source projects (i.e.-[http://en.wikipedia.org/wiki/Apache_Software_Foundation Apache Software  Foundation],[http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby],[http://en.wikipedia.org/wiki/SourceForge SourceForge],[http://en.wikipedia.org/wiki/Tigris.org Tigris.org], [http://en.wikipedia.org/wiki/PHP PHP],  [http://en.wikipedia.org/wiki/Python_(programming_language) Python] and [http://en.wikipedia.org/wiki/MediaWiki MediaWiki]) use Subversion. Subversion is an open source software due to it's Apache license[1]. [[Image:Subversion_project_visualization.svg.png|650px|thumb|center|Visualization of a very simple Subversion project. Source:wikimedia commons, Explanation of terms can be found at http://en.wikipedia.org/wiki/Apache_Subversion, &amp;quot;Branching and tagging&amp;quot; and at http://en.wikipedia.org/wiki/Revision_control, #&amp;quot;Common vocabulary&amp;quot;]]&lt;br /&gt;
#'''[http://en.wikipedia.org/wiki/IBM_Configuration_Management_Version_Control_(CMVC) Configuration Management Version Control (CMVC)]''' developed by IBM Corporation in the mid-late 1990s and was derived in part from software purchased from HP and from IBM's internal-use-only system, IDSS. CMVC was superseded by IBM Rational ClearCase and ClearQuest. The system was used to manage the IBM OS/2 and IBM AIX source code repositories in the 1990s. It is still widely used within IBM by various teams.&lt;br /&gt;
:One of the drawbacks of CMVC is that, once a file is checked-out by a user, it remains locked to all the other users until the either the new version is checked-in or the lock is released explicitly by the owner (user) of the lock.&lt;br /&gt;
# Some proprietary client-server based version control softwares are-&lt;br /&gt;
#:*[http://en.wikipedia.org/wiki/Autodesk_Vault Autodesk Vault] was specifically developed for Autodesk applications.&lt;br /&gt;
#:*[http://en.wikipedia.org/wiki/IBM_Rational_ClearCase ClearCase] was developed by IBM Rational Software. It's a Source Code Control (SCC) compliant software.&lt;br /&gt;
#:*[http://en.wikipedia.org/wiki/Visual_SourceSafe Visual SourceSafe] is developed by Microsoft targeting small development team.&lt;br /&gt;
#:*[http://en.wikipedia.org/wiki/Visual_Studio_Team_System Visual Studio Team System] is also developed by Microsoft targeting larger groups.&lt;br /&gt;
&lt;br /&gt;
===Distributed model===&lt;br /&gt;
'''Distributed Version Control (DVCS)''', or '''Decentralized Version Control''' systems can have many central repositories.This is a peer to peer approach. The concept started developing at late 90's. In DVCS. Each developer works with his or her local repository and the changes are synchronized between repositories upon commit. DVCS are better suited for large teams with partially independent developers. i.e.- opensource software development.[8]&lt;br /&gt;
##[http://en.wikipedia.org/wiki/Monotone_%28software%29 Monotone] and [http://en.wikipedia.org/wiki/GNU_arch GNU arch]  were the first generation DVCS (release:2001-2003) followed by [http://en.wikipedia.org/wiki/Darcs Darcs] (stable release:2010).[http://en.wikipedia.org/wiki/Mercurial Mercurial] , [http://en.wikipedia.org/wiki/Git_%28software%29 Git] and [http://en.wikipedia.org/wiki/Bazaar_%28software%29 Bazaar] (2005-2007) are well adopted among developers.   &lt;br /&gt;
##[http://en.wikipedia.org/wiki/BitKeeper BitKeeper],[http://en.wikipedia.org/wiki/Code_Co-op Code Co-op], [http://en.wikipedia.org/wiki/Sun_WorkShop_TeamWare Sun WorkShop TeamWare] are some proprietary DVCS softwares.&lt;br /&gt;
&lt;br /&gt;
It should be noted that many distributed version control softwares support client-server model too.One of the benefits of DVCS is that a developer can save the source code as long as he wants even if the central repository (in client-server model) is discarded at the end of a project.&lt;br /&gt;
&lt;br /&gt;
[[Image:timeline.jpg|650px|thumb|center|A generalized timeline. Source:http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki1a_5_History_of_version_control_by_av]]&lt;br /&gt;
&lt;br /&gt;
== File Sharing Models ==&lt;br /&gt;
Every system that implement version controlling have to address one fundamental problem: How will the files in the repository be safely shared across users but prevent them from accidentally stepping on each other's feet? It's all too easy for users to accidentally overwrite each other's changes in the repository.&lt;br /&gt;
&lt;br /&gt;
Consider the scenario with two users A and B. Both of them check out the same file (same version). User A after making his modification, suppose, commits the file first. A few moments later B completes his modification. B does not have any clue about A's check-in and he happily commits his code to the repository. Now B has accidentally overwritten the changes made by A leaving the system in an inconsistent state. This problem can be solved in two different ways:&amp;lt;br/&amp;gt;&lt;br /&gt;
* Lock-Modify-Unlock&lt;br /&gt;
* Copy-Modify-Merge &amp;lt;br/&amp;gt;&lt;br /&gt;
While CMVC follows the lock-modify-unlock solution, svn follows copy-modify-merge allowing users to modify the same piece of code concurrently. &amp;lt;br/&amp;gt;&lt;br /&gt;
The problem with the lock-modify-unlock model is that it's a bit restrictive and often becomes a roadblock for users:&lt;br /&gt;
&lt;br /&gt;
Locking may cause administrative problems. Sometimes user A will lock a file and then forget about it. Meanwhile, because B is still waiting to edit the file, his hands are tied. And then A goes on vacation. Now B has to get an administrator to release A's lock. The situation ends up causing a lot of unnecessary delay and wasted time.&lt;br /&gt;
&lt;br /&gt;
Locking may cause unnecessary serialization. What if A is editing the beginning of a text file, and B simply wants to edit the end of the same file? These changes don't overlap at all. They could easily edit the file simultaneously, and no great harm would come, assuming the changes were properly merged together. There's no need for them to take turns in this situation.&lt;br /&gt;
&lt;br /&gt;
Locking may create a false sense of security. Suppose A locks and edits file f1, while Sally simultaneously locks and edits file f2. But what if f1 and f2 depend on one another, and the changes made to each are semantically incompatible? Suddenly f1 and f2 don't work together anymore. The locking system was powerless to prevent the problem—yet it somehow provided a false sense of security. It's easy for A and B to imagine that by locking files, each is beginning a safe, insulated task, and thus they need not bother discussing their incompatible changes early on. Locking often becomes a substitute for real communication. &amp;lt;REVISIT&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use of version control in other areas ==&lt;br /&gt;
&lt;br /&gt;
Now a days, many document editing softwares have adopted version control. Wikis, GoogleDoc, Microsoft Office and OpenOffice.org suite are some example softwares that can save previous document editing history. &lt;br /&gt;
&lt;br /&gt;
==Other considerations==&lt;br /&gt;
&lt;br /&gt;
Most open source softwares have [http://linuxmafia.com/faq/Apps/vcs.html distributions for Linux] OS. In most open source cases, Linux and windows versions are released concurrently. &lt;br /&gt;
Many VCS' have plugins for common IDEs like Eclipse, Visual Studio, Oracle JDeveloper etc. NetBeans IDE and Xcode has integrated version control support.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
1. [http://subversion.apache.org/news.html#news-20100217.  Apache Software Foundation Announcements, &amp;quot;Subversion becomes Apache Subversion&amp;quot;.(2010-02-17) Accessed:September 2010 ]&lt;br /&gt;
&lt;br /&gt;
2. [http://svnbook.red-bean.com/ Ben Collins-Sussman, Brian W. Fitzpatrick, C. Michael Pilato. &amp;quot;Version Control with Subversion&amp;quot;, an O'Reilly book available online. Accessed:September 2010] &lt;br /&gt;
&lt;br /&gt;
3. [http://shop.oreilly.com/product/9781565921177.do Don Bolinger, Tan Bronson: Applying RCS and SCCS. O'Reilly Media. ISBN:978-1-56592-117-7]  &lt;br /&gt;
&lt;br /&gt;
4. [http://www.ericsink.com/scm/source_control.html  Eric Sink: A collection of articles on source control and best practices, Accessed:September 2010]&lt;br /&gt;
&lt;br /&gt;
5. [http://basepath.com/aup/talks/SCCS-Slideshow.pdf  M. J. Rochkind: The Source Code Control System.] In IEEE Transactions on Software Engineering SE-1:4 (Dec. 1975), pages 364–370.&lt;br /&gt;
&lt;br /&gt;
6. [http://onlinelibrary.wiley.com/doi/10.1002/bltj.2039/pdf Martin, Robert L. (2002). &amp;quot;Software configuration management for the 21st century&amp;quot;. Bell Labs technical journal, Volume 2, Issue 1, page- 154.]&lt;br /&gt;
&lt;br /&gt;
7. Mike Mason; Pragmatic Version Control Using Subversion; Pragmatic Bookshelf; ISBN 0-9745140-6-3 (1st edition, paperback, 2005)&lt;br /&gt;
&lt;br /&gt;
8. [http://www.ibm.com/developerworks/aix/library/au-dist_ver_control/ Noah Gift,Adam Shand: Introduction to distributed version control systems (compare how to use Bazaar, Mercurial, and Git) (Apr 2009), IBM Technical Library, Accessed:September 2010 ] &lt;br /&gt;
&lt;br /&gt;
9.[http://onlinelibrary.wiley.com/doi/10.1002/spe.4380150703/abstract Walter F. Tichy; Rcs - a system for version control; In Software: Practice and Experience. Volume 15, Issue 7,(July 1985) pages 637–654 ]&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Revision_control Wikipedia: Revision control]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/List_of_revision_control_software Wikipedia: List of revision control software]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Comparison_of_revision_control_software Wikipedia: Detail comparison of revision control softwares]&lt;br /&gt;
&lt;br /&gt;
[http://www.nongnu.org/cvs/ CVS webpage]&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.vu.nl/~dick/  Dick Grune's website on CVS history]&lt;br /&gt;
&lt;br /&gt;
[http://groups.google.com/group/mod.sources/msg/2ebab72ac0744fb8?dmode=source The original usenet post on CVS] archived at google groups.&lt;br /&gt;
&lt;br /&gt;
[http://linuxmafia.com/faq/Apps/vcs.html Linux availability of various version control softwares]&lt;/div&gt;</summary>
		<author><name>Karthi2</name></author>
	</entry>
</feed>