Allows a class to reuse the code from another class without duplicating it
Inheritance
Parent class has properties and methods, child class can use the code from the parent class
Allows you to write the code in the parent class and use it in both parent and child classes
Parent class
Also called a base class or super class
Child class
Also known as a derived class or a subclass
Defining a class that inherits from another class
Use the extends keyword
Interface
Establishes a contract that a class must adhere to, a blueprint for classes
Interfaces
Specify what methods a class should implement
Declared with the interface keyword
Consist of methods with no implementations, all methods must have public visibility
Classes can implement one or more interfaces
Classes must implement all the methods defined in an interface
Can be extended using the extends operator
Can contain methods and/or constants, but no attributes
The class which implements an interface is called the Concrete Class
Interfaces allow you to specify what methods a class should implement
Interfaces are different from classes as the class can inherit from one class only whereas the class can implement one or more interfaces
Interfaces can be extended to another interface
A class implements an interface using the implements operator
Design patterns
Typical solutions to commonly occurring problems in software design, pre-made blueprints that can be customized
Patterns vs Algorithms
Algorithm defines a clear set of actions to achieve a goal, pattern is a high-level description of a solution
Patterns were first described by Christopher Alexander in A Pattern Language: Towns, Buildings, Construction
The concept of design patterns was applied to programming by Erich Gamma, John Vlissides, Ralph Johnson, and Richard Helm in their 1994 book Design Patterns: Elements of Reusable Object-Oriented Software
Most programmers work for many years without knowing about a single pattern, they might be even implementing some patterns without knowing it
Why learn design patterns
They are a toolkit of tried and tested solutions to common problems in software design, teach principles of object-oriented design, provide a common language for communication
Criticism of design patterns
Kludges for a weak programming language
Inefficient solutions
Unjustified use
Classification of design patterns
Idioms are basic, low-level patterns that apply to a single programming language
Architectural patterns are the most universal, high-level patterns that can be used to design the architecture of an entire application