- Code should be written like poetry
- Authors of Design patterns are Gang of Four, Erich Gamma, Richard Helm, Ralph Johnson and John Vlissidies in the year 1994
- Whenever 'new' is called use - Creational
- Use of class hierarchies and relationships - Structural
- Increase the flexibility in carrying out communication - Behavioral
- Instead of beating around the bush and jumping to coding right away, first analyse the requirements and design the solution
- Before even making a single line of code change, understand the design flow, that might take time initially but would save a lot of time later and avoid run necessary bugs and issues
- Use flow charts, data flow diagrams, time sequence diagrams and all other design tools available to draw and understand design
- A successful software in one which is secure, usable, performs well and satisfies all user requirements
- This can be achieved with correct design and accurate implementation
-
On the journey of creating successful software several engineers have faced commonly occurring design issues related to memory leak, object creation, classes structuring, components communication and wiring.
-
Documented these problems and solutions for other engineers benefit as design patterns
- Design pattern is a general repeatable solution to a commonly occurring problem in a software design.
- It includes some of the best practices adapted by experienced object-oriented software developers.
- It describes the problem, the solution, when to apply the solution, and its consequences
- It is a ready-made templates that can be applied to your own designs to solve common problems which could be related to object creation, object communication, class structuring or anything else
- It gives a leg-up in creating flexible and maintainable object-oriented systems
- Makes your life easier by not reinventing the wheel.
- Use the power of a shared vocabulary
- Solve issues even before they become visible
- Better code quality
- Improve your object-oriented skills
- Recognise the patterns in libraries and languages
- Give you an extra edge for job and promotion
- Spaghetti Code
- Cut-and-Paste Programming
- It is a mechanism in which one object acquires all the properties and behaviours of the parent object
- It allows programmers to create classes that are built upon existing classes, to specify a new implementation to maintain the same behaviour to reuse code
- Inheritance causes issues which coding as changes in the base classes will require more QA testing
- Is your code dry or wet?
- DRY - Don't Repeat Yourself is a software development principle, the main aim of which is to reduce repetition of code
- WET - Write Every Time is a cheeky abbreviation to mean the opposite, that is, code that doesn't adhere to DRY Principle
- Bad Software Characteristics - Rigidity, Fragility, Immobility
- Software Design Principles
S.O.L.I.D
acronym- It stands for:
S
Single responsibility principleO
Open Closed PrincipleL
Liskov substitution principleI
Interface segregation principleD
Dependency inversion principle
- Lower the program's cyclomatic complexity, lower the risk to modify and easier to understand
- Formula -
E-N+2*P
E
= number of edges in the flow graphN
= number of nodes in the flow graphP
= number of nodes that have exit points
- It is when a group of classes is highly dependent on a one another
- Minor changes in one class creates a ripple effect and causes modification in too many changes
- Interface helps in decoupling
- Be a software doctor
- Understand the memory issue
- Recognise the pattern of problems and design solutions around it
- What is an Object ?
- An object consist of:
State
represented by attributes or properties of an objectBehaviour
represented by methods of an objectIdentity
gives a unique identifier to an object also called as reference object
- An object consist of:
- Philosophy behind Categorization
- Object is created from a class which has certain behaviour and is structured in certain way to communicate:
- Creational Patterns,
- It defines the best possible way to instantiate an object while hiding the creation logic
- Types:
- Builder
- Singleton
- Factory Method
- Abstract Method
- Prototype
- Structural Patterns,
- It describes how objects and classes can be combined to form larger structures
- Types:
- Adaptor
- Bridge
- Composite
- Decorator
- Facade
- Proxy
- Behavioral Patterns,
- Patterns specifically concerned with communication (interaction) between the objects. The interactions between the objects should be such that they are talking to each other and still are loosely coupled,
- Types
- Strategy
- Command
- Interpreter
- Iterator
- Chain of Responsibility
- Mediator
- Memento
- Observer
- State
- Template
- Visitor
- Creational Patterns,
- Object is created from a class which has certain behaviour and is structured in certain way to communicate:
- Singleton Pattern
- Factory Pattern
- Template Patterns
- Observer-Observable
- Proxy