SlideShare a Scribd company logo
Software Design Principles
and Best Practices
Satyajit Dey
Technical Lead
Cefalo Bangladesh Ltd
Technical Debt
Metaphor coined by Ward Cunningham in a 1992 report.
A concept in software development that reflects the implied
cost of additional rework caused by choosing an easy
solution now instead of using a better approach that would
take longer.
Stakeholders Goals
● Determine product/market fit
● Critical need to ship products early
● Meet customer needs
● Seize emerging opportunities
Causes of Technical Debt
● Business pressure
● Lack of understanding of the consequences of technical debt
● Failing to combat the strict coherence of components
● Lack of tests
● Lack of documentation
● Lack of interaction between team members
● Long-term simultaneous development in several branches
● Delayed refactoring
● Lack of compliance monitoring
● Incompetence
Types of Technical Debt
1. Code debt
2. Design & Architecture debt
3. Test debt
4. Documentation debt
Technical Debt
Figure - Technical debt: The vicious cycle
Code Smells
A code smell is a surface indication that usually
corresponds to a deeper problem in the system.
—Martin Fowler
Common Code Smells
● Comments
● Uncommunicative Name
● Long method
● Duplicate Code
● Data Clumps
● Primitive Obsession
● Divergent Code
● Shotgun Surgery
● Switch Statements
● Lazy Class
And many more…..
Comments
● Should only be used to clarify "why" not "what".
● Can quickly become verbose and reduce code clarity.
Please don’t do that.
Uncommunicative Name
● Choose names that communicate intent
● Pick the best name for the time, change it later if necessary
Long Method
Signs and Symptoms
A method contains too many lines of code.
Reason
Developers start coding without reading the existing implementation.
Treatment
● Extract Method
● Replace Method with Method Object
Duplicate Code
Signs and Symptoms
Code fragments look almost identical.
Reasons for the Problem
● Multiple programmers doing same thing at the same time
● Novice programmers may not resist themselves to do Copy/Pasta
● Scary authors don’t allow to refactor their code
Treatment
● Extract Method
● Pull Up Field
● Form Template Method, Substitute Algorithm
Data Clumps
Signs and Symptoms
Sometimes different parts of the code contain identical groups of variables
Reasons for the Problem
● Copypasta programming
Treatment
● Extract Class
● Introduce Parameter Object
Primitive Obsession
Signs and Symptoms
Use of primitives instead of small objects for simple tasks
Reasons for the Problem
● “Just a field for storing some data!” the programmer said
● Creating a primitive field is easier
Treatment
● Replace Data values with Object
Divergent Change
Signs and Symptoms
You find yourself having to change many unrelated methods when you make changes
to a class
Reasons for the Problem
● Often these divergent modifications are due to poor program structure or
"copypasta programming”.
Treatment
● Split up the behavior of the class via Extract Class.
Shotgun Surgery
Signs and Symptoms
A single change impact many other classes.
Reasons for the Problem
● Poor separation of concerns.
● Failure to understand responsibilities(SRP)
Treatment
● Move Method
● Move Field
● Inline Class.
Switch Statements
Signs and Symptoms
You have a complex switch operator or sequence of if statements.
Reasons for the Problem
● Switch Statements can be scattered in several places
● Need to find all SS for adding new case.
Treatment
● Think about Polymorphism
Lazy Class
Signs and Symptoms
If a class doesn’t do enough to earn your attention, it should be deleted.
Reasons for the Problem
● After refactoring the Class has become less important
● May be designed for future needs!
Treatment
● Inline Class
● Collapse Hierarchy.
Design Principle
A set of guidelines that helps us to avoid having a bad design.
According to Robert Martin 3 important characteristics of a bad design should be
avoided:
● Rigidity
● Fragility
● Immobility
Two Minutes on Coupling
SOLID
S - Single Responsibility Principle
O - Open-closed Principle
L - Liskov Substitution Principle
I - Interface Segregation Principle
D - Dependency Inversion Principle
Single Responsibility Principle(SRP)
A class should have one, and only one, reason to change.
● One class should only serve one purpose
● All the methods and properties should all work towards the same goal
● When a class serves multiple purposes or responsibility then it should be made
into a new class
Open-Closed Principle(OCP)
Entities should be open for extension, but closed for
modification.
● Add new functionality without changing the existing code
● Use abstraction over implementation
● Helps us to build loosely coupled system
Liskov Substitution Principle(LSP)
Let q(x) be a property provable about objects of x of type T. Then
q(y) should be provable for objects y of type S where S is a
subtype of T.
Every subclass/derived class should be substitutable for their
base/parent class.
Interface Segregation Principle(ISP)
A client should never be forced to implement an interface
that it doesn’t use or clients shouldn’t be forced to depend on
methods they do not use.
Dependency Inversion Principle(DI)
Entities must depend on abstractions not on concretions. It
states that the high level module must not depend on the low
level module, but they should depend on abstractions
Dependency Inversion Principle(DI)
Fig: Procedural System Fig: Object Oriented System
“Any fool can write code that a computer can understand. Good
programmers write code that humans can understand.”
― Martin Fowler
https://github.com/Cefalo/lets-learn-refactoring
Refactoring: Sample Source Code
Thank You

More Related Content

What's hot

Class 7 lecture notes
Class 7 lecture notesClass 7 lecture notes
Class 7 lecture notes
Stephen Parsons
 
Algorithms
AlgorithmsAlgorithms
Algorithms
AlgorithmsAlgorithms
Steps for Developing a 'C' program
 Steps for Developing a 'C' program Steps for Developing a 'C' program
Steps for Developing a 'C' programSahithi Naraparaju
 
Algorithms and flow charts
Algorithms and flow chartsAlgorithms and flow charts
Algorithms and flow charts
Chinnu Edwin
 
Test Driven Development (TDD) Basics
Test Driven Development (TDD) BasicsTest Driven Development (TDD) Basics
Test Driven Development (TDD) Basics
Carlos Andrés Oquendo
 
Staroletov Design by Contract, verification of Cyber-physical systems
Staroletov Design by Contract, verification of Cyber-physical systemsStaroletov Design by Contract, verification of Cyber-physical systems
Staroletov Design by Contract, verification of Cyber-physical systems
Sergey Staroletov
 
Week10 final
Week10 finalWeek10 final
Week10 final
Irfan Ali Memon
 
Understanding, measuring and improving code quality in JavaScript
Understanding, measuring and improving code quality in JavaScriptUnderstanding, measuring and improving code quality in JavaScript
Understanding, measuring and improving code quality in JavaScriptMark Daggett
 
Python: Object-oriented Testing
Python: Object-oriented TestingPython: Object-oriented Testing
Python: Object-oriented Testing
Damian T. Gordon
 
Algorithms
AlgorithmsAlgorithms
Csc1100 lecture01 ch01 pt2-paradigm
Csc1100 lecture01 ch01 pt2-paradigmCsc1100 lecture01 ch01 pt2-paradigm
Csc1100 lecture01 ch01 pt2-paradigm
IIUM
 
Unit 3 Control Flow Testing
Unit 3   Control Flow TestingUnit 3   Control Flow Testing
Unit 3 Control Flow Testing
ravikhimani
 
Algorithms
AlgorithmsAlgorithms
Developers on test
Developers on testDevelopers on test
Developers on test
Datio Big Data
 
Fundamentals of programming)
Fundamentals of programming)Fundamentals of programming)
Fundamentals of programming)
jakejakejake2
 
Qat09 presentations dxw07u
Qat09 presentations dxw07uQat09 presentations dxw07u
Qat09 presentations dxw07uShubham Sharma
 

What's hot (20)

Quick Intro to Clean Coding
Quick Intro to Clean CodingQuick Intro to Clean Coding
Quick Intro to Clean Coding
 
Programming and problem solving with c++, 3rd edition
Programming and problem solving with c++, 3rd editionProgramming and problem solving with c++, 3rd edition
Programming and problem solving with c++, 3rd edition
 
Class 7 lecture notes
Class 7 lecture notesClass 7 lecture notes
Class 7 lecture notes
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Steps for Developing a 'C' program
 Steps for Developing a 'C' program Steps for Developing a 'C' program
Steps for Developing a 'C' program
 
Algorithms and flow charts
Algorithms and flow chartsAlgorithms and flow charts
Algorithms and flow charts
 
Test Driven Development (TDD) Basics
Test Driven Development (TDD) BasicsTest Driven Development (TDD) Basics
Test Driven Development (TDD) Basics
 
Staroletov Design by Contract, verification of Cyber-physical systems
Staroletov Design by Contract, verification of Cyber-physical systemsStaroletov Design by Contract, verification of Cyber-physical systems
Staroletov Design by Contract, verification of Cyber-physical systems
 
Week10 final
Week10 finalWeek10 final
Week10 final
 
Understanding, measuring and improving code quality in JavaScript
Understanding, measuring and improving code quality in JavaScriptUnderstanding, measuring and improving code quality in JavaScript
Understanding, measuring and improving code quality in JavaScript
 
Python: Object-oriented Testing
Python: Object-oriented TestingPython: Object-oriented Testing
Python: Object-oriented Testing
 
Testing techniques
Testing techniquesTesting techniques
Testing techniques
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Csc1100 lecture01 ch01 pt2-paradigm
Csc1100 lecture01 ch01 pt2-paradigmCsc1100 lecture01 ch01 pt2-paradigm
Csc1100 lecture01 ch01 pt2-paradigm
 
Unit 3 Control Flow Testing
Unit 3   Control Flow TestingUnit 3   Control Flow Testing
Unit 3 Control Flow Testing
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Developers on test
Developers on testDevelopers on test
Developers on test
 
Fundamentals of programming)
Fundamentals of programming)Fundamentals of programming)
Fundamentals of programming)
 
Qat09 presentations dxw07u
Qat09 presentations dxw07uQat09 presentations dxw07u
Qat09 presentations dxw07u
 

Similar to Software Design Principles and Best Practices - Satyajit Dey

Single Responsibility Principle
Single Responsibility PrincipleSingle Responsibility Principle
Single Responsibility Principle
BADR
 
Object Oriented, Design patterns and data modelling worshop
Object Oriented, Design patterns and data modelling worshopObject Oriented, Design patterns and data modelling worshop
Object Oriented, Design patterns and data modelling worshop
Mohammad Shawahneh
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytech
yannick grenzinger
 
Keeping code clean
Keeping code cleanKeeping code clean
Keeping code clean
Brett Child
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2
Knoldus Inc.
 
Entity Framework: To the Unit of Work Design Pattern and Beyond
Entity Framework: To the Unit of Work Design Pattern and BeyondEntity Framework: To the Unit of Work Design Pattern and Beyond
Entity Framework: To the Unit of Work Design Pattern and Beyond
Steve Westgarth
 
DesignPrinciples-and-DesignPatterns
DesignPrinciples-and-DesignPatternsDesignPrinciples-and-DesignPatterns
DesignPrinciples-and-DesignPatterns
Basavaraj Patil
 
Design poo my_jug_en_ppt
Design poo my_jug_en_pptDesign poo my_jug_en_ppt
Design poo my_jug_en_ppt
agnes_crepet
 
Improving your code design using Java
Improving your code design using JavaImproving your code design using Java
Improving your code design using Java
Roan Brasil Monteiro
 
L05 Design Patterns
L05 Design PatternsL05 Design Patterns
L05 Design Patterns
Ólafur Andri Ragnarsson
 
The OO Design Principles
The OO Design PrinciplesThe OO Design Principles
The OO Design Principles
Steve Zhang
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
deonpmeyer
 
System Development Life Cycle Models
System Development Life Cycle ModelsSystem Development Life Cycle Models
System Development Life Cycle Models
Pavithran Anthonipillai
 
From class to architecture
From class to architectureFrom class to architecture
From class to architecture
Marcin Hawraniak
 
Solid principles
Solid principlesSolid principles
Solid principles
Kumaresh Chandra Baruri
 
Evgeniy Khyst - why does software design matter and how to keep it in good shape
Evgeniy Khyst - why does software design matter and how to keep it in good shapeEvgeniy Khyst - why does software design matter and how to keep it in good shape
Evgeniy Khyst - why does software design matter and how to keep it in good shape
Anna Shymchenko
 
From Good to SOLID: How to become a better PHP developer
From Good to SOLID: How to become a better PHP developerFrom Good to SOLID: How to become a better PHP developer
From Good to SOLID: How to become a better PHP developer
Katerina Trajchevska
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptx
anguraju1
 
Better java with design
Better java with designBetter java with design
Better java with design
Narayann Swaami
 
Software development fundamentals
Software development fundamentalsSoftware development fundamentals
Software development fundamentals
Alfred Jett Grandeza
 

Similar to Software Design Principles and Best Practices - Satyajit Dey (20)

Single Responsibility Principle
Single Responsibility PrincipleSingle Responsibility Principle
Single Responsibility Principle
 
Object Oriented, Design patterns and data modelling worshop
Object Oriented, Design patterns and data modelling worshopObject Oriented, Design patterns and data modelling worshop
Object Oriented, Design patterns and data modelling worshop
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytech
 
Keeping code clean
Keeping code cleanKeeping code clean
Keeping code clean
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2
 
Entity Framework: To the Unit of Work Design Pattern and Beyond
Entity Framework: To the Unit of Work Design Pattern and BeyondEntity Framework: To the Unit of Work Design Pattern and Beyond
Entity Framework: To the Unit of Work Design Pattern and Beyond
 
DesignPrinciples-and-DesignPatterns
DesignPrinciples-and-DesignPatternsDesignPrinciples-and-DesignPatterns
DesignPrinciples-and-DesignPatterns
 
Design poo my_jug_en_ppt
Design poo my_jug_en_pptDesign poo my_jug_en_ppt
Design poo my_jug_en_ppt
 
Improving your code design using Java
Improving your code design using JavaImproving your code design using Java
Improving your code design using Java
 
L05 Design Patterns
L05 Design PatternsL05 Design Patterns
L05 Design Patterns
 
The OO Design Principles
The OO Design PrinciplesThe OO Design Principles
The OO Design Principles
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
 
System Development Life Cycle Models
System Development Life Cycle ModelsSystem Development Life Cycle Models
System Development Life Cycle Models
 
From class to architecture
From class to architectureFrom class to architecture
From class to architecture
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Evgeniy Khyst - why does software design matter and how to keep it in good shape
Evgeniy Khyst - why does software design matter and how to keep it in good shapeEvgeniy Khyst - why does software design matter and how to keep it in good shape
Evgeniy Khyst - why does software design matter and how to keep it in good shape
 
From Good to SOLID: How to become a better PHP developer
From Good to SOLID: How to become a better PHP developerFrom Good to SOLID: How to become a better PHP developer
From Good to SOLID: How to become a better PHP developer
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptx
 
Better java with design
Better java with designBetter java with design
Better java with design
 
Software development fundamentals
Software development fundamentalsSoftware development fundamentals
Software development fundamentals
 

More from Cefalo

Overview of Cookies in HTTP - Miran al Mehrab
Overview of Cookies in HTTP - Miran al MehrabOverview of Cookies in HTTP - Miran al Mehrab
Overview of Cookies in HTTP - Miran al Mehrab
Cefalo
 
Handshaking with HTTPS - Rafiul Islam
Handshaking with HTTPS - Rafiul IslamHandshaking with HTTPS - Rafiul Islam
Handshaking with HTTPS - Rafiul Islam
Cefalo
 
Evolution of HTTP - Miran Al Mehrab
Evolution of HTTP - Miran Al MehrabEvolution of HTTP - Miran Al Mehrab
Evolution of HTTP - Miran Al Mehrab
Cefalo
 
Content Negotiation in HTTP - Ibnul Tahsin Bhuiyan
Content Negotiation in HTTP - Ibnul Tahsin BhuiyanContent Negotiation in HTTP - Ibnul Tahsin Bhuiyan
Content Negotiation in HTTP - Ibnul Tahsin Bhuiyan
Cefalo
 
Conditional Requests in HTTP - Nafis Fuad
Conditional Requests in HTTP - Nafis FuadConditional Requests in HTTP - Nafis Fuad
Conditional Requests in HTTP - Nafis Fuad
Cefalo
 
Tips to kick-start your Software Engineering Career - Ferdous Mahmud Shaon
Tips to kick-start your Software Engineering Career - Ferdous Mahmud ShaonTips to kick-start your Software Engineering Career - Ferdous Mahmud Shaon
Tips to kick-start your Software Engineering Career - Ferdous Mahmud Shaon
Cefalo
 
Rest API Authentication - Uttom Akash
Rest API Authentication - Uttom AkashRest API Authentication - Uttom Akash
Rest API Authentication - Uttom Akash
Cefalo
 
Overview of REST - Raihan Ullah
Overview of REST - Raihan UllahOverview of REST - Raihan Ullah
Overview of REST - Raihan Ullah
Cefalo
 
Getting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonGetting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud Shaon
Cefalo
 
Brief of Caching - Rafiul Islam
Brief of Caching - Rafiul IslamBrief of Caching - Rafiul Islam
Brief of Caching - Rafiul Islam
Cefalo
 
Basics of HTTP - Nafis Fuad
Basics of HTTP - Nafis FuadBasics of HTTP - Nafis Fuad
Basics of HTTP - Nafis Fuad
Cefalo
 
Cross Origin Resource Sharing (CORS) - Azizul Hakim
Cross Origin Resource Sharing (CORS) - Azizul HakimCross Origin Resource Sharing (CORS) - Azizul Hakim
Cross Origin Resource Sharing (CORS) - Azizul Hakim
Cefalo
 

More from Cefalo (12)

Overview of Cookies in HTTP - Miran al Mehrab
Overview of Cookies in HTTP - Miran al MehrabOverview of Cookies in HTTP - Miran al Mehrab
Overview of Cookies in HTTP - Miran al Mehrab
 
Handshaking with HTTPS - Rafiul Islam
Handshaking with HTTPS - Rafiul IslamHandshaking with HTTPS - Rafiul Islam
Handshaking with HTTPS - Rafiul Islam
 
Evolution of HTTP - Miran Al Mehrab
Evolution of HTTP - Miran Al MehrabEvolution of HTTP - Miran Al Mehrab
Evolution of HTTP - Miran Al Mehrab
 
Content Negotiation in HTTP - Ibnul Tahsin Bhuiyan
Content Negotiation in HTTP - Ibnul Tahsin BhuiyanContent Negotiation in HTTP - Ibnul Tahsin Bhuiyan
Content Negotiation in HTTP - Ibnul Tahsin Bhuiyan
 
Conditional Requests in HTTP - Nafis Fuad
Conditional Requests in HTTP - Nafis FuadConditional Requests in HTTP - Nafis Fuad
Conditional Requests in HTTP - Nafis Fuad
 
Tips to kick-start your Software Engineering Career - Ferdous Mahmud Shaon
Tips to kick-start your Software Engineering Career - Ferdous Mahmud ShaonTips to kick-start your Software Engineering Career - Ferdous Mahmud Shaon
Tips to kick-start your Software Engineering Career - Ferdous Mahmud Shaon
 
Rest API Authentication - Uttom Akash
Rest API Authentication - Uttom AkashRest API Authentication - Uttom Akash
Rest API Authentication - Uttom Akash
 
Overview of REST - Raihan Ullah
Overview of REST - Raihan UllahOverview of REST - Raihan Ullah
Overview of REST - Raihan Ullah
 
Getting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonGetting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud Shaon
 
Brief of Caching - Rafiul Islam
Brief of Caching - Rafiul IslamBrief of Caching - Rafiul Islam
Brief of Caching - Rafiul Islam
 
Basics of HTTP - Nafis Fuad
Basics of HTTP - Nafis FuadBasics of HTTP - Nafis Fuad
Basics of HTTP - Nafis Fuad
 
Cross Origin Resource Sharing (CORS) - Azizul Hakim
Cross Origin Resource Sharing (CORS) - Azizul HakimCross Origin Resource Sharing (CORS) - Azizul Hakim
Cross Origin Resource Sharing (CORS) - Azizul Hakim
 

Recently uploaded

Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 

Recently uploaded (20)

Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 

Software Design Principles and Best Practices - Satyajit Dey

  • 1. Software Design Principles and Best Practices Satyajit Dey Technical Lead Cefalo Bangladesh Ltd
  • 2. Technical Debt Metaphor coined by Ward Cunningham in a 1992 report. A concept in software development that reflects the implied cost of additional rework caused by choosing an easy solution now instead of using a better approach that would take longer.
  • 3. Stakeholders Goals ● Determine product/market fit ● Critical need to ship products early ● Meet customer needs ● Seize emerging opportunities
  • 4. Causes of Technical Debt ● Business pressure ● Lack of understanding of the consequences of technical debt ● Failing to combat the strict coherence of components ● Lack of tests ● Lack of documentation ● Lack of interaction between team members ● Long-term simultaneous development in several branches ● Delayed refactoring ● Lack of compliance monitoring ● Incompetence
  • 5. Types of Technical Debt 1. Code debt 2. Design & Architecture debt 3. Test debt 4. Documentation debt
  • 6. Technical Debt Figure - Technical debt: The vicious cycle
  • 7. Code Smells A code smell is a surface indication that usually corresponds to a deeper problem in the system. —Martin Fowler
  • 8. Common Code Smells ● Comments ● Uncommunicative Name ● Long method ● Duplicate Code ● Data Clumps ● Primitive Obsession ● Divergent Code ● Shotgun Surgery ● Switch Statements ● Lazy Class And many more…..
  • 9. Comments ● Should only be used to clarify "why" not "what". ● Can quickly become verbose and reduce code clarity. Please don’t do that.
  • 10. Uncommunicative Name ● Choose names that communicate intent ● Pick the best name for the time, change it later if necessary
  • 11. Long Method Signs and Symptoms A method contains too many lines of code. Reason Developers start coding without reading the existing implementation. Treatment ● Extract Method ● Replace Method with Method Object
  • 12. Duplicate Code Signs and Symptoms Code fragments look almost identical. Reasons for the Problem ● Multiple programmers doing same thing at the same time ● Novice programmers may not resist themselves to do Copy/Pasta ● Scary authors don’t allow to refactor their code Treatment ● Extract Method ● Pull Up Field ● Form Template Method, Substitute Algorithm
  • 13. Data Clumps Signs and Symptoms Sometimes different parts of the code contain identical groups of variables Reasons for the Problem ● Copypasta programming Treatment ● Extract Class ● Introduce Parameter Object
  • 14. Primitive Obsession Signs and Symptoms Use of primitives instead of small objects for simple tasks Reasons for the Problem ● “Just a field for storing some data!” the programmer said ● Creating a primitive field is easier Treatment ● Replace Data values with Object
  • 15. Divergent Change Signs and Symptoms You find yourself having to change many unrelated methods when you make changes to a class Reasons for the Problem ● Often these divergent modifications are due to poor program structure or "copypasta programming”. Treatment ● Split up the behavior of the class via Extract Class.
  • 16. Shotgun Surgery Signs and Symptoms A single change impact many other classes. Reasons for the Problem ● Poor separation of concerns. ● Failure to understand responsibilities(SRP) Treatment ● Move Method ● Move Field ● Inline Class.
  • 17. Switch Statements Signs and Symptoms You have a complex switch operator or sequence of if statements. Reasons for the Problem ● Switch Statements can be scattered in several places ● Need to find all SS for adding new case. Treatment ● Think about Polymorphism
  • 18. Lazy Class Signs and Symptoms If a class doesn’t do enough to earn your attention, it should be deleted. Reasons for the Problem ● After refactoring the Class has become less important ● May be designed for future needs! Treatment ● Inline Class ● Collapse Hierarchy.
  • 19. Design Principle A set of guidelines that helps us to avoid having a bad design. According to Robert Martin 3 important characteristics of a bad design should be avoided: ● Rigidity ● Fragility ● Immobility
  • 20. Two Minutes on Coupling
  • 21. SOLID S - Single Responsibility Principle O - Open-closed Principle L - Liskov Substitution Principle I - Interface Segregation Principle D - Dependency Inversion Principle
  • 22. Single Responsibility Principle(SRP) A class should have one, and only one, reason to change. ● One class should only serve one purpose ● All the methods and properties should all work towards the same goal ● When a class serves multiple purposes or responsibility then it should be made into a new class
  • 23. Open-Closed Principle(OCP) Entities should be open for extension, but closed for modification. ● Add new functionality without changing the existing code ● Use abstraction over implementation ● Helps us to build loosely coupled system
  • 24. Liskov Substitution Principle(LSP) Let q(x) be a property provable about objects of x of type T. Then q(y) should be provable for objects y of type S where S is a subtype of T. Every subclass/derived class should be substitutable for their base/parent class.
  • 25. Interface Segregation Principle(ISP) A client should never be forced to implement an interface that it doesn’t use or clients shouldn’t be forced to depend on methods they do not use.
  • 26. Dependency Inversion Principle(DI) Entities must depend on abstractions not on concretions. It states that the high level module must not depend on the low level module, but they should depend on abstractions
  • 27. Dependency Inversion Principle(DI) Fig: Procedural System Fig: Object Oriented System
  • 28. “Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” ― Martin Fowler

Editor's Notes

  1. Sometimes stakeholders set unrealistic deadline of a project.
  2. We treat everything in the trash as another trash, no matters it is valuable or less valuable
  3. Generally, any method longer than ten lines should make you start asking questions. The majority of a programmer’s time is spent reading code rather than writing code It is usually a sign that the method has too many responsibilities Long methods make code hard to maintain and debug
  4. For example: (such as parameters for connecting to a database)
  5. Primitive obsessions are born in moments of weakness Then another field was needed and added in the same way.
  6. For example, when adding a new product type you have to change the methods for finding, displaying, and ordering products. Payoff Improves code organization. Reduces code duplication. Simplifies support.
  7. Shotgun Surgery resembles Divergent Change but is actually the opposite smell. Divergent Change is when many changes are made to a single class. Shotgun Surgery refers to when a single change is made to multiple classes simultaneously
  8. spreading around logic that should probably be in one place if you add a value to one switch statement you’re likely to need to hunt down all the other ones and change them too. Cyclometic complexity = Number of decisions in the source code
  9. Rigidity - It is hard to change because every change affects too many other parts of the system. Fragility - When you make a change, unexpected parts of the system break. Immobility - It is hard to reuse in another application because it cannot be disentangled from the current application.
  10. Primitive obsessions are born in moments of weakness Then another field was needed and added in the same way. It doesn’t mean a class will have only one Method. All the methods should be related to the Goal of the class.
  11. It’s not only a Principle. We can call it a CONTRACT If a feature/method is specially handled for a given Subclass there is a violation of LSP. For example A getChildren() method of a non-leaf node returns all it’s children but a leaf node might throw exception in this case. Which is clear violation of LSP.
  12. An example could be AnimalSound interface with bark, mew and moo. In that case Dog, Cat and Cow need to implement relevant methods from that interface.
  13. Tight coupling between Layers & Sub-layers Any change in the sub-layer will have a ripple effect in the next higher layer and may propagate even further upwards In Object Oriented System both High & Low modules depends on abstraction. So as long is the contract of abstraction is maintained the system will remain flexible.
  14. May be I can share the what Yves told me at Nandos regarding code refactoring & code quality.