code structural analysis

27
Code structural analysis

Upload: neueda

Post on 08-May-2015

1.110 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Code Structural Analysis

Code structural analysis

Page 2: Code Structural Analysis

2

Speaker

Eduards Sizovs

4finance | Software Architect

linkedin.com/in/eduardsi

[email protected]

Page 3: Code Structural Analysis

3

Agenda

• Introduction to structural analysis

• Package Cohesion principles

• Package Coupling principles

• Class design principles

• Stan4j in action

Page 4: Code Structural Analysis

4

Introduction to structural analysis

Page 5: Code Structural Analysis

5

Software Artifact

Application

Libraries

Packages

Classes

Members

Design layer

Code layer

Page 6: Code Structural Analysis

6

• How artifacts build into higher level artifacts

• How artifacts depend on each other

Software Structure

Page 7: Code Structural Analysis

7

Big ball of mud

Page 8: Code Structural Analysis

8

• Rigidity

• Fragility

• Immobility

• Viscosity

• Opacity

Rotting structure symptoms

Page 9: Code Structural Analysis

9

• Early fixing design violations

• Keeping code complexity on a manageable level under constant change rain

• Getting the «big picture»

Goals of structural analysis

Page 10: Code Structural Analysis

10

Structural clarity

Page 11: Code Structural Analysis

11

Package Cohesion principles

Page 12: Code Structural Analysis

12

Release Reuse Equivalency

«The unit of reuse is the unit of release»

Criterion for grouping artifacts is convenience for reuse and release

Component

lv.jug.api

lv.jug.logic

Page 13: Code Structural Analysis

13

Common Closure Principle

«Classes that change together belong together»

If classes that change together are in the same Package, then the impact on other packages is

minimized. Group classes open to certain changes.

lv.jug.domain.client

lv.jug.dao.client

lv.jug.service.client

lv.jug.domain.client

Page 14: Code Structural Analysis

14

Common Reuse Principle

«Classes in a package are reused together»

A dependency upon a package is a dependency upon everything within the package.

Page 15: Code Structural Analysis

15

Package Coupling principles

Page 16: Code Structural Analysis

16

Can be solved by:

• Splitting packages (CRP)

• Reorganizing packages

• DIP & Interface Segregation

Acyclic Dependencies Principle

«The dependencies between packages must not form cycles»

Page 17: Code Structural Analysis

17

Abstractness of a package

A(P) = AC(P) / TC(P)A(P) ∈ [ 0..1 ]

…where

P = package

AC = abstract type count

TC = total type count

Page 18: Code Structural Analysis

18

Instability of a package

I(P) = EC(P) / ( AC(P) + EC(P) )A(P) ∈ [ 0..1 ]

…where

P = package

EC (Efferent Coupling) = number of outgoing dependencies

AC (Afferent Coupling) = number of incoming dependencies

Page 19: Code Structural Analysis

19

Stable Abstractions Principle

«A package should be as abstract as it is stable»

Distance (D)

D = A + I - 1

Zone of pain

Zone of uselessness

Page 20: Code Structural Analysis

20

D-metric Plot

Page 21: Code Structural Analysis

21

Stable Dependencies Principle

«Depend in the direction of stability»

Page 22: Code Structural Analysis

22

Class design principles (SOLID)

Page 23: Code Structural Analysis

23

Dependency Inversion Principle

«Depend on abstractions, as anything concrete is volatile»

Page 24: Code Structural Analysis

24

Interface Segregation Principle

«Many client specific interfaces are better than one general purpose interface»

Page 25: Code Structural Analysis

25

Stan4j in action

Page 26: Code Structural Analysis

26

More

Page 27: Code Structural Analysis

27

Thank you!

4finance