---
# System prepended metadata

title: Head first design pattern easy (Chapter 1)
tags: [OOP, Design pattern]

---

Head first design pattern easy (Chapter 1)
===
###### tags: `OOP` `Design pattern`
1. Identify the aspect of your application that vary and separate them from what stays the same
2. Program to an interface, not implementation
3. The declared type of the variable should be a supertype, usually abstract class or Java interface (Animal a=new Dog();) or even better, assign the concrete implementation object at runtime, so as to reuse behaviour classes
4. A duck just allows the object that is referenced by quackBehaviour to quack for it
5. Setting behaviour dynamically
6. Extends : This is used to get attributes of a parent class into child class and may contain already defined methods that can be overridden in the child class.
7. Implements : This is used to implement an interface (parent class with functions signatures only but not their definitions) by defining it in the child class.
8. Favor composition over inheritance
9. Strategy pattern defines a family of algorithms, encapsulates each one, and make them interchangable. Strategy lets the algorithm vary independently from clients that use it
10. Observer pattern: The observer pattern is a software design pattern in which an object, named the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.
11. Design pattern helps you think in a pattern level, accelerate communication
12. Abstraction (hide unwanted information), encapsulation (hide data into single entity for secure reason) While encapsulation is the process or method to contain the information. In abstraction, problems are solved at the design or interface level
![](https://i.imgur.com/vvuEW6M.png)
