Remodelling overall app so that new features can fit up or you can optimize overall app for achieving readability, extensibility, ...
Display only essential information and hide details
Binding data and behaviour into single unit
Perform same thing in different ways
Sub class inherits properties and methods from base class
1. Association
- Biderictional relationship b/w classes
- 1 to *
- * to 1
- 1 to 1
2. Composition
- Part cannot exist without Whole
3. Aggregation
- Whole-Part relationship
- Class contains object of another class but contained object can exist independently
4. Generatlization
- IS A relationship
- like inheritance
- conventions
- create maintainable, extensible, flexible s/w
- SOLID principle provides/helps
- Testing
- Modularity
- Coupling
- A class should have only one reason/responsibility to change.
- class adheres to SRP
- Identify responsibility
- Separation of concerns
- Scenarios that violate SRP
- God class
- split into smaller classes handling single reposibility
- God class
- A class should be open for extension but closed for modification
- Base/Derieved class pointer should be interchangeable
- object of super class should be easily replecable with object of subclass
- subclass should preserve behavior of superclass
- requires
- Behavorieal Presentation
- A class should not "forced to" implement interfaces or implement interface methods which it does not require
- remove/avoid unnecessary dependencies
- flexibility/dependencies
- What should not do
- Avoid bloating
- Use interface/abstract class for dependency rather concrete implementation
- loose coupling
- Flexible, easier to test, maintable
- Typical solutions to commonly occurring problems in software design.
- Blueprints that can be used to customize to solve a particular design problem in your code.
- Well known way of solving a well known problem. (Template for solving problem)
- Simpler communication in one phrase
-
Creational
-
- Seperate construction of object from its representation.
- avoiding a constructor with numerous parameters
- Perform validations
- Creation of object is easier and resillient
- Director - any class orchestrates the construction process using builder interface to construct actual objects.
- Final objects return to client by Director
- complexity
- enhancement
- loose coupling
- extensibility
-
- Segregating the logic for creating the object wherever required
-
- Cloning of the object (based on the existing ones)
- Document Management system (clone document)
- DB entity (clone db entity)
- configuration management
-
- Single object getting created throughout the scope of execution.
- Can achieve thread safety
-
- Interface for Factory of similar objects without concrete classes
-
-
Behavioral
-
- Allows an object to pass through a chain of handler.
- Handlers will decide either to process or pass the request to next handler.
-
- Required when want to convert Actions/Requests/Methods into first class entity(object)
- Encapsulates the requests as an object which allows parameterization of client
-
- For notifications
- Observer
- Observable
- One to Many relationship
- change in 1 leads to chnage in multiple
- without making tightly coupled
- dynamic chnages in number of observers and their types
- when to use
- Flexibilty & decoupling
- Real-Time updates
- Dynamic Relationships
-
- selecting algorithm or behaviour at runtime
- encourages composition over inheritance
-
- allow state change when behaviour is going to be chnaged
- encapsulation of the behavior associated with the state
- Behavior of a particular classes and entities
- deals with conditional aspects
- context - mantains current state of the object
-
Structural
-
- Allows objects with incompatible interfaces to work together.
- Acting as a bridge b/w incompatible interfaces
- "adpats" the interface of one class to match interface of another class
- usability
- Integrate with 3rd party libraries or APIs
- Legacy System Interoperability
- Interface Standardization in Large Systems
-
- add additional responsibilities dynamically
- used with Inheritance
- used for Open Closed Principle
- maintains interface to pizza object
- Structure
- Component
- ConcreteComponent
- Decorator (Wrapper along with Reference to component)
- Concrete Decorator
- example: Pizza, Coffee, Premium subscription
-
- Placeholder to control and access another object without modifying the code
- lazy loading of object or initialization on demand
- control access. example security construct
- Usage & Usability
- Adding layer of control over real object
- lazy loading of expensive operation
- access control from the object
- Use cases
- Caching
- Logging
- Login
-
- Way to hide complexity of a subsystem.
- "Do not expose what is not necessary" principle
- loose coupling
- high level user-friendly interface
- encourages encapsulation
- separation of concerns so that client have easiness to use the subsystem
-
Use when dealing FINITE set of things
POJO manager, if required
- as a enum
- In inheritance - bound to use everything as a part of subclass
- In composition - it is providing flixibility, encapsulation, easily extensible, easily modifiable, decoupled
- Composition avoids Diamond problem
1. Names of variables
2.
3. Comments
eg. counter++; // Adding 1 to counter X
counter++; // Incrementing counter
4. Cormatting/Indentation
5. Avoiding Magic numbers
6. Exception
7. Duplicate code avoiding (DRY)
8. Single Responsibility principle
9. Methods/Codebase should be small
10. Classes should be small
11. Clean/readable Unit test + cover all scenarios (very important)