SlideShare ist ein Scribd-Unternehmen logo
1 von 54
Code Structural Analysis
Eduards Sizovs
eduards.sizovs@gmail.com
www.linkedin.com/in/eduardsi
@eduardsi on Twitter
Who is broadcasting?
Agenda
• Introduction to structural analysis
• Logical Design principles
• Q&A
Introduction to structural analysis
Most apps begin life
small and neat.
Time goes by…
Hello.
I am your rotting
enterprise app.
How do we feel design rot?
Rigidity
Fragility
Immobility
Viscosity
Opacity
Needless Complexity
Needless Repetition
There are different symptoms that smell…
What structural analysis shows…
Structure of Hibernate Core 3.6.6
Artwork by Jackson Pollock
However, it could be better…
Structure of Spring Framework 3.2.0
Structural analysis allows you to keep app’s
structure in shape and catch design flaws
early.
Logical Design principles
Package is the first-class citizen and key
element of logical design.
Treat packages as hierarchical even if
they’re represented flat.
Given packages
com.myproject.client
com.myproject.client.personal
com.myproject.client.profile
com.myproject.api
Personal and Profile packages are part of Client.
Use packages to group functionally-related
artifacts. Do not group artifacts that do the
same thing, but are different by nature.
Avoid
com.myproject.enums
com.myproject.model
com.myproject.services
com.myproject.repository
com.myproject.factory
com.myproject.helpers
…
Prefer
com.myproject.client
com.myproject.lending
com.myproject.loyality
…
The Common Closure Principle
Group tightly coupled classes together. If
classes that change together are in the same
package, then the impact of change is
localized.
Make sure artifacts are not floating away.
Make packages highly cohesive by following
Single Responsibility Principle.
Keep packages loosely coupled, ideally –
completely independent. Reflection doesn’t
count.
Avoid dependency magnets. Sometimes
duplication is not that evil.
Aggregate root relationship
com.app.loan
class Loan {
}
com.app.client
class Client {
// a bunch of stuff
}
@ManyToOne
Client client
Aggregate root relationship
com.app.loan
class Loan {
}
com.app.client
class Client {
// a bunch of stuff
}
@Embedded
ClientId clientId
com.app.client
@Embeddable
class ClientId {
Long value
}
Provide slim package interface and hide
implementation details.
Strive for weak package connascence. Keep
locality in mind.
Manage relationships. Every dependency
arrow has a reason. Burn bi-directional
dependences in fire.
Otherwise
Version 1.0 – A great start
Version 1.1 – Imperfection creeps in
Version 1.2 – Imperfection takes hold
Version 1.3 – Chaos begins
Version 1.4 – Explosion
The Acyclic Dependencies Principle
The dependencies between packages must
not form cycles.
Can be solved by:
- Merging
- Dependency Inversion
- Escalation
- Demotion
Client.Beans
Merging
Client
Client
Tracking
Dependency Inversion
Guest
TrackingGuest
Billing
Escalation
Customer
class Customer {
Collection<Bill> bills
def calculateDiscount() { }
}
class Bill {
def pay(Customer customer) {
customer.calculateDiscount()
…
}
}
Billing
Escalation
Customer
class Customer {
Collection<Bill> bills
}
class Bill {
def pay(BigDecimal discount) {
}
}
class DiscountCalculator {
def calculate(Customer, Bills)
}
Discount
Billing
Demotion
Customer
class Customer {
Collection<Bill> bills
def getDiscountCalculator()
}
class Bill {
def pay(DiscountCalculator) { }
}
class DiscountCalculator {
def calculate()
}
Discount
Class design principles (SOLID)
Single Responsibility Principle
Open-Closed Principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion Principle
Class should have only one responsibility and only one
reason to change.
The Single Responsibility Principle
Depend on abstractions, as anything concrete is volatile
The Dependency Inversion Principle
High Level
Policy
Abstraction Abstraction
Impl. Impl.
Package Package
X Y
X Y
interface
X
Package Package
Client
B
Service
«Client A method»
«Client B method»
«Client C method»
Client
C
Client
A
Many client-specific interfaces are better than one
general-purpose interface
The Interface Segregation Principle
Interface A
«Client A method»
Client
B
Client
C
Client
A
Interface B
«Client B method»
Interface C
«Client C method»
Service
«Client A method»
«Client B method»
«Client C method»
Tools
Macker
JDepend
OO Design Principles & Metrics, Jason Gorman http://goo.gl/RTW9GT
The Economics of Software Design, J.B. Rainsberger http://goo.gl/ra7Q8Q
SOLID Principles, Eduards Sizovs http://goo.gl/Rpxavd
Designing Object-Oriented Software, Jouni Smed http://goo.gl/iyE1R2
Grand Unified Theory Of Software Design, Jim Weirich http://goo.gl/ASqyAs
Fun With Modules, Kirk Knoernschild http://goo.gl/i8jx8Y
More
Conclusion
Every application requires structure.
Structure must be carefully managed.
Integrate Code Structural Analysis into development:
• Install CSA tool
• Look at the «big picture»
• Manage complexity
• Prevent entropy
Wish you beautiful architectures.
Thank you!

Weitere ähnliche Inhalte

Was ist angesagt?

Self-Service Operations: Because Ops Still Happens
Self-Service Operations: Because Ops Still HappensSelf-Service Operations: Because Ops Still Happens
Self-Service Operations: Because Ops Still Happens
Rundeck
 
Helping Ops Help You: Development’s Role in Enabling Self-Service Operations
Helping Ops Help You:  Development’s Role in Enabling Self-Service OperationsHelping Ops Help You:  Development’s Role in Enabling Self-Service Operations
Helping Ops Help You: Development’s Role in Enabling Self-Service Operations
Rundeck
 
10 Reasons Your Software Sucks - Election 2012 Edition
10 Reasons Your Software Sucks - Election 2012 Edition10 Reasons Your Software Sucks - Election 2012 Edition
10 Reasons Your Software Sucks - Election 2012 Edition
Caleb Jenkins
 
Neal Ford Emergent Design And Evolutionary Architecture
Neal Ford Emergent Design And Evolutionary ArchitectureNeal Ford Emergent Design And Evolutionary Architecture
Neal Ford Emergent Design And Evolutionary Architecture
Thoughtworks
 

Was ist angesagt? (20)

Operations as a Service: Because Failure Still Happens
Operations as a Service: Because Failure Still Happens Operations as a Service: Because Failure Still Happens
Operations as a Service: Because Failure Still Happens
 
The "Ops" Side of DevSecOps
The "Ops" Side of DevSecOps The "Ops" Side of DevSecOps
The "Ops" Side of DevSecOps
 
Incident Management in the Age of DevOps and SRE
Incident Management in the Age of DevOps and SRE Incident Management in the Age of DevOps and SRE
Incident Management in the Age of DevOps and SRE
 
Self-Service Operations: Because Ops Still Happens
Self-Service Operations: Because Ops Still HappensSelf-Service Operations: Because Ops Still Happens
Self-Service Operations: Because Ops Still Happens
 
How HipChat Ships and Recovers Fast with DevOps Practices
How HipChat Ships and Recovers Fast with DevOps PracticesHow HipChat Ships and Recovers Fast with DevOps Practices
How HipChat Ships and Recovers Fast with DevOps Practices
 
Scaling Scrum with UX in the Enterprise
Scaling Scrum with UX in the EnterpriseScaling Scrum with UX in the Enterprise
Scaling Scrum with UX in the Enterprise
 
Expecto Performa! The Magic and Reality of Performance Tuning
Expecto Performa! The Magic and Reality of Performance TuningExpecto Performa! The Magic and Reality of Performance Tuning
Expecto Performa! The Magic and Reality of Performance Tuning
 
Helping Ops Help You: Development’s Role in Enabling Self-Service Operations
Helping Ops Help You:  Development’s Role in Enabling Self-Service OperationsHelping Ops Help You:  Development’s Role in Enabling Self-Service Operations
Helping Ops Help You: Development’s Role in Enabling Self-Service Operations
 
Incident Management in the Age of DevOps and SRE
Incident Management in the Age of DevOps and SRE Incident Management in the Age of DevOps and SRE
Incident Management in the Age of DevOps and SRE
 
Beyond Agile and DevOps: From Concepts to Products in Weeks, Not Months
Beyond Agile and DevOps: From Concepts to Products in Weeks, Not MonthsBeyond Agile and DevOps: From Concepts to Products in Weeks, Not Months
Beyond Agile and DevOps: From Concepts to Products in Weeks, Not Months
 
Embracing Jira Cloud: Tips from an ex-Server admin
Embracing Jira Cloud: Tips from an ex-Server adminEmbracing Jira Cloud: Tips from an ex-Server admin
Embracing Jira Cloud: Tips from an ex-Server admin
 
Operations: The Last Mile
Operations: The Last Mile Operations: The Last Mile
Operations: The Last Mile
 
If your team is an object what is its API?
If your team is an object what is its API?If your team is an object what is its API?
If your team is an object what is its API?
 
State of Drupal keynote, DrupalCon Austin
State of Drupal keynote, DrupalCon AustinState of Drupal keynote, DrupalCon Austin
State of Drupal keynote, DrupalCon Austin
 
Go or No-Go: Operability and Contingency Planning at Etsy.com
Go or No-Go: Operability and Contingency Planning at Etsy.comGo or No-Go: Operability and Contingency Planning at Etsy.com
Go or No-Go: Operability and Contingency Planning at Etsy.com
 
10 Reasons Your Software Sucks - Election 2012 Edition
10 Reasons Your Software Sucks - Election 2012 Edition10 Reasons Your Software Sucks - Election 2012 Edition
10 Reasons Your Software Sucks - Election 2012 Edition
 
Ops Happens: Improving Incident Response Using DevOps and SRE Practices
Ops Happens:  Improving Incident Response Using DevOps and SRE PracticesOps Happens:  Improving Incident Response Using DevOps and SRE Practices
Ops Happens: Improving Incident Response Using DevOps and SRE Practices
 
Plugin style EA
Plugin style EAPlugin style EA
Plugin style EA
 
SRE for Everyone: Making Tomorrow Better Than Today
SRE for Everyone: Making Tomorrow Better Than Today SRE for Everyone: Making Tomorrow Better Than Today
SRE for Everyone: Making Tomorrow Better Than Today
 
Neal Ford Emergent Design And Evolutionary Architecture
Neal Ford Emergent Design And Evolutionary ArchitectureNeal Ford Emergent Design And Evolutionary Architecture
Neal Ford Emergent Design And Evolutionary Architecture
 

Ähnlich wie Code Structural Analysis

Sofwear deasign and need of design pattern
Sofwear deasign and need of design patternSofwear deasign and need of design pattern
Sofwear deasign and need of design pattern
chetankane
 
Software architecture-patterns
Software architecture-patternsSoftware architecture-patterns
Software architecture-patterns
pedro
 
software-architecture-patterns
software-architecture-patternssoftware-architecture-patterns
software-architecture-patterns
Pallav Kumar
 
The State of Front-end At CrowdTwist
The State of Front-end At CrowdTwistThe State of Front-end At CrowdTwist
The State of Front-end At CrowdTwist
Mark Fayngersh
 
(E book pdf) thinking in patterns with java
(E book   pdf) thinking in patterns with java(E book   pdf) thinking in patterns with java
(E book pdf) thinking in patterns with java
Raffaella D'angelo
 
Agile Software Architecture
Agile Software ArchitectureAgile Software Architecture
Agile Software Architecture
cesarioramos
 
Chapter4 high-level-design
Chapter4 high-level-designChapter4 high-level-design
Chapter4 high-level-design
Vin Voro
 
Part C Developing Your Design SolutionThe Production Cycle.docx
Part C Developing Your Design SolutionThe Production Cycle.docxPart C Developing Your Design SolutionThe Production Cycle.docx
Part C Developing Your Design SolutionThe Production Cycle.docx
smile790243
 

Ähnlich wie Code Structural Analysis (20)

Sofwear deasign and need of design pattern
Sofwear deasign and need of design patternSofwear deasign and need of design pattern
Sofwear deasign and need of design pattern
 
Software architecture-patterns
Software architecture-patternsSoftware architecture-patterns
Software architecture-patterns
 
Software arquitectura patron diseño
Software arquitectura patron diseñoSoftware arquitectura patron diseño
Software arquitectura patron diseño
 
software-architecture-patterns
software-architecture-patternssoftware-architecture-patterns
software-architecture-patterns
 
The State of Front-end At CrowdTwist
The State of Front-end At CrowdTwistThe State of Front-end At CrowdTwist
The State of Front-end At CrowdTwist
 
Grokking Techtalk: Problem solving for sw engineers
Grokking Techtalk: Problem solving for sw engineersGrokking Techtalk: Problem solving for sw engineers
Grokking Techtalk: Problem solving for sw engineers
 
Unit 2
Unit 2Unit 2
Unit 2
 
(E book pdf) thinking in patterns with java
(E book   pdf) thinking in patterns with java(E book   pdf) thinking in patterns with java
(E book pdf) thinking in patterns with java
 
Software Design principales
Software Design principalesSoftware Design principales
Software Design principales
 
Agile Software Architecture
Agile Software ArchitectureAgile Software Architecture
Agile Software Architecture
 
OOSAD Chapter 6 Object Oriented Design.pptx
OOSAD Chapter 6 Object Oriented Design.pptxOOSAD Chapter 6 Object Oriented Design.pptx
OOSAD Chapter 6 Object Oriented Design.pptx
 
Lec18
Lec18Lec18
Lec18
 
Design concepts and principle,
Design concepts and principle, Design concepts and principle,
Design concepts and principle,
 
Chapter4 high-level-design
Chapter4 high-level-designChapter4 high-level-design
Chapter4 high-level-design
 
Thoughtful Software Design
Thoughtful Software DesignThoughtful Software Design
Thoughtful Software Design
 
Part C Developing Your Design SolutionThe Production Cycle.docx
Part C Developing Your Design SolutionThe Production Cycle.docxPart C Developing Your Design SolutionThe Production Cycle.docx
Part C Developing Your Design SolutionThe Production Cycle.docx
 
M03_1_Structur alDiagrams.ppt
M03_1_Structur                         alDiagrams.pptM03_1_Structur                         alDiagrams.ppt
M03_1_Structur alDiagrams.ppt
 
Tool Driven Restructuring of Large Codebases
Tool Driven Restructuring of Large CodebasesTool Driven Restructuring of Large Codebases
Tool Driven Restructuring of Large Codebases
 
Code Complexity.pdf
Code Complexity.pdfCode Complexity.pdf
Code Complexity.pdf
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and Design
 

Mehr von Eduards Sizovs

Micro Service Architecture
Micro Service ArchitectureMicro Service Architecture
Micro Service Architecture
Eduards Sizovs
 

Mehr von Eduards Sizovs (9)

Beyond Software Craftsmanship - Johnny's Road to Remarkable Career
Beyond Software Craftsmanship - Johnny's Road to Remarkable CareerBeyond Software Craftsmanship - Johnny's Road to Remarkable Career
Beyond Software Craftsmanship - Johnny's Road to Remarkable Career
 
Architecting well-structured Java applications
Architecting well-structured Java applicationsArchitecting well-structured Java applications
Architecting well-structured Java applications
 
Continuous Delivery (The newest)
Continuous Delivery (The newest)Continuous Delivery (The newest)
Continuous Delivery (The newest)
 
Software Craftsmanship Essentials
Software Craftsmanship EssentialsSoftware Craftsmanship Essentials
Software Craftsmanship Essentials
 
Micro Service Architecture
Micro Service ArchitectureMicro Service Architecture
Micro Service Architecture
 
Continuous Delivery
Continuous DeliveryContinuous Delivery
Continuous Delivery
 
SOLID
SOLIDSOLID
SOLID
 
Introduction to DDD
Introduction to DDDIntroduction to DDD
Introduction to DDD
 
Code Structural Analysis
Code Structural AnalysisCode Structural Analysis
Code Structural Analysis
 

Kürzlich hochgeladen

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Kürzlich hochgeladen (20)

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 

Code Structural Analysis

Hinweis der Redaktion

  1. Rigidity (стойкость) – изменение аффектит слишком много зависимостей (МНОГО ЗАВИСИМОСТЕЙ ОТ МОДУЛЯ)Fragility (хрупкость) – поломка в разных местах без конфептуальной связиImmobility (немобильность, тяжеловесность) – невозможность зареюзать компоненты, хвост зависимостей, сложно сделать декомпозицию (МНОГО ТЯНЕТ ЗА СОБОЙ КУЧУ)Viscosity (вязкость) – when normal change is harder to employ than hack due to design (not clear wtf) or environment (compilation 1H)Opacity – не понятна суть и предназначение артифакта, взаимосвязиNeedless Complexity – чтобы сделать что-нибудь, приходится городитьNeedless Repetition – один и тот же функционал в разных кодовых проявлениях
  2. - Being Related!= Part of- Packages under Client can be tightly coupled. With an API around.- An Aggregate Root with aggregates + functions- Or a Bounded context, for example.
  3. It’s not about slices-first/layers-first fighting. It’s about grouping artifacts that are closely related.“DDD” packagingFunctional components are not visible at all. How to find relations between functional items. “What if I add this, how would it impact my functionality”?What should I do to extract functionality into a separate module? FAT is high that will force you to break logical module into functional. Then you’ll end up with mess managing this layering.Ok, provide API on top.
  4. Shotgun surgery instead of localized changes (imagine I move client somewhere). Imagine I put a class that changes frequently into unrelated package. It will change every time as well!
  5. I gain portability!!!For example, when mapping relationships, map using ID instead of Entity.Independence – talk to as few as possible. We become mobile, don’t care about incoming/outgoing dependencies
  6. E.g. Client is used everywhere! Consider creating different clients. Ideally client can have different forms: Visitor, Client, Lender… Break client into smaller partsAbstract if there is chance that client code will have different cadence (out of release scope)
  7. Be conservative in what you expose.Introduce factories that hide implementations (Dependency Injection, Service Locators etc.)Make @Components package-privateSeparate “api” from “internal” packages and restrict access to “internal”Make sure “internal” depends on “api”, not opposite.
  8. Two components are connascent if a change in one would require the other to be modified in order to maintain the overall correctness of the system.Strongconnescence – worse.Problem of connascence of order -&gt; in order to achieve goal X, client package A has to invoke two methods from package B. If package A decide that B has to call something in between, or order change, it will break B. Solution: provide coarse-grained interface for goal X, for example.For example: Connascence of Name over Connescance of Entity when desigining entity relationships.
  9. Reasons:No guidelines for developers.Unable to simply extract: unable to “levelize” to see what to physically extract for build parallelization