Skip to content

blaze-b/java-design-patterns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

JAVA Design Patterns

  • 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

Follow Pattern Categories

  • Whenever 'new' is called use - Creational
  • Use of class hierarchies and relationships - Structural
  • Increase the flexibility in carrying out communication - Behavioral

Better Coding Should bring in easier understandability

Design first Approach

  • 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

Successful Software

  • 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

Journey of creating Successful Software

  • 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

  • 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

Advantages

  • 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

Anti-pattern of Software

  • Spaghetti Code
  • Cut-and-Paste Programming

Design Patterns are language independent

Object Inheritance

  • 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

Code Reusability

  • 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 principle
        • O Open Closed Principle
        • L Liskov substitution principle
        • I Interface segregation principle
        • D Dependency inversion principle

Cyclomatic Complexity

  • 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 graph
    • N = number of nodes in the flow graph
    • P = number of nodes that have exit points

Tight Coupling

  • 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

Recognise the pattern of problems ans design solutions

  • Be a software doctor
  • Understand the memory issue
  • Recognise the pattern of problems and design solutions around it

Design Patterns Categorization

  • What is an Object ?
    • An object consist of:
      • State represented by attributes or properties of an object
      • Behaviour represented by methods of an object
      • Identity gives a unique identifier to an object also called as reference object
  • 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

Design Patterns used in the Spring Framework

  • Singleton Pattern
  • Factory Pattern
  • Template Patterns
  • Observer-Observable
  • Proxy

About

A complete guide of all the Java Design patterns for better coding practices

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages