Inside ArchitectureWhat I meant to say at dotnetsheff 2016/08/02
Zeb MasonCopyright © 2016 by Zeb Mason
Agenda: Frivolity, Theory & Tools
Copyright © 2016 by Zeb Mason
The Colosseum
Copyright © 2016 by Zeb Mason
The Colosseum
RomeCopyright © 2016 by Zeb Mason
Roman Architecture?
Copyright © 2016 by Zeb Mason
Yes
Copyright © 2016 by Zeb Mason
Yes
and noCopyright © 2016 by Zeb Mason
Framework Architecture
Copyright © 2016 by Zeb Mason
Framework Architecture
Why?Copyright © 2016 by Zeb Mason
It’s full of holes!
Copyright © 2016 by Zeb Mason
The humble scarab beetle
Copyright © 2016 by Zeb Mason
Ancient Egyptians saw the god Ra rolling the
sun around the heavens
Copyright © 2016 by Zeb Mason
But is this how you feel when trying to get to
grips with your code?
Copyright © 2016 by Zeb Mason
Note that’s not a big ball of mud
Architects draw
Architecture
in Visio
Copyright © 2016 by Zeb Mason
Architects draw
Architecture Marketing
in Visio
Copyright © 2016 by Zeb Mason
Architecture Marketing
Copyright © 2016 by Zeb Mason
Markitecture
Copyright © 2016 by Zeb Mason
Markitecture
Copyright © 2016 by Zeb Mason
Markitecture
Box
Copyright © 2016 by Zeb Mason
Markitecture
Box
in a box
Copyright © 2016 by Zeb Mason
Markitecture
Box
in a box
in a box
Copyright © 2016 by Zeb Mason
Markitecture
Box
in a box
in a box
to keep
things tidy
Copyright © 2016 by Zeb Mason
Markitecture
Gradient fill
implies
vague
boundaries?
Copyright © 2016 by Zeb Mason
Theory
Leonhard Euler
Copyright © 2016 by Zeb Mason
The Seven Bridges of Königsberg
Copyright © 2016 by Zeb Mason
Graph Theory
Copyright © 2016 by Zeb Mason
Directed graphs
C
B D
A
Copyright © 2016 by Zeb Mason
Structure matrix
C
B D
A
A B C D
A
B 1
C 1 1
D
Copyright © 2016 by Zeb Mason
Sorted
C
B D
A
A B D C
A
B 1
D
C 1 1
Copyright © 2016 by Zeb Mason
Cycles don’t sort out
C
B D
A
A B D C E
A
B 1 1
D
C 1 1
E 1
E
Copyright © 2016 by Zeb Mason
Carl Friedrich Gauss
Copyright © 2016 by Zeb Mason
Triangular numbers
•Add 1 + 2 + 3 + … + N
Copyright © 2016 by Zeb Mason
Triangular numbers
•Add 1 + 2 + 3 + … + N
•Add N + N-1 + … + 1
Copyright © 2016 by Zeb Mason
Triangular numbers
•Add 1 + 2 + 3 + … + N
•Add N + N-1 + … + 1
•So N lots of N + 1
Copyright © 2016 by Zeb Mason
Triangular numbers
•Add 1 + 2 + 3 + … + N
•Add N + N-1 + … + 1
•So N lots of N + 1
•Sum is
1
2
𝑁(𝑁 + 1)
Copyright © 2016 by Zeb Mason
Triangular numbers
•Add 1 + 2 + 3 + … + N
•Add N + N-1 + … + 1
•So N lots of N + 1
•Sum is
1
2
𝑁(𝑁 + 1)
•Schoolboy maths!
Copyright © 2016 by Zeb Mason
Edges in a graph
•Undirected graph
•N nodes
•+1 node => +N edges
•i.e. triangular number
•Max 𝑁(𝑁 − 1)/2
edges
•Directed graph
•Double the sum
•Max 𝑁(𝑁 − 1) edges
Copyright © 2016 by Zeb Mason
Edges in a graph
•Undirected graph
•N nodes
•+1 node => +N edges
•i.e. triangular number
•Max 𝑁(𝑁 − 1)/2
edges
•Directed graph
•Double the sum
•Max 𝑁(𝑁 − 1) edges
Copyright © 2016 by Zeb Mason
Edges in a graph
•Undirected graph
•N nodes
•+1 node => +N edges
•i.e. triangular number
•Max 𝑁(𝑁 − 1)/2
edges
•Directed graph
•Double the sum
•Max 𝑁(𝑁 − 1) edges
Copyright © 2016 by Zeb Mason
Metrics
Cyclomatic number:
E + P – N
Cyclomatic complexity:
E + 2P – N
where
E is the number of edges
P is the number of parts
Copyright © 2016 by Zeb Mason
Metric invariance
Cyclomatic number:
E + P – N
= 2 + 1 – 3
= 0
Copyright © 2016 by Zeb Mason
Metric invariance
Cyclomatic number:
E + P – N
= 2 + 2 – 4
= 0
Copyright © 2016 by Zeb Mason
Metric invariance
Cyclomatic number:
E + P – N
= 3 + 1 – 4
= 0
Copyright © 2016 by Zeb Mason
Metric invariance
Cyclomatic number:
E + P – N
= 2 + 1 – 3
+ 1 + 1 – 2
= 0
Copyright © 2016 by Zeb Mason
Spot the difference
3 layer
architecture
3 tier
architecture
A
B
C
A
B
C
Copyright © 2016 by Zeb Mason
Spot the difference
3 layer
architecture
3 tier
architecture
A
B
C
A
B
C
using B
Copyright © 2016 by Zeb Mason
Spot the difference
3 layer
architecture
3 tier
architecture
A
B
C
A
B
C
using C
using B
Copyright © 2016 by Zeb Mason
Spot the difference
3 layer
architecture
3 tier
architecture
A
B
C
A
B
C
address of B
using C
using B
Copyright © 2016 by Zeb Mason
Spot the difference
3 layer
architecture
3 tier
architecture
A
B
C
A
B
C
address of B
address of Cusing C
using B
Copyright © 2016 by Zeb Mason
Find architecture patterns in code
• Dependency analysis
• e.g. Layered architecture
• Heap analysis
• e.g. Tiered architecture
• Change in heap
• e.g.
Copyright © 2016 by Zeb Mason
Find design patterns in code
• Dependency analysis
• e.g. Factory method
• Heap analysis
• e.g.
• Change in heap
• e.g.
Copyright © 2016 by Zeb Mason
Find design patterns in code
• Dependency analysis
• e.g. Factory method
• Heap analysis
• e.g. Composite
• Change in heap
• e.g.
Copyright © 2016 by Zeb Mason
Find design patterns in code
• Dependency analysis
• e.g. Factory method
• Heap analysis
• e.g. Composite
• Change in heap
• e.g. State machine
Copyright © 2016 by Zeb Mason
Tools
•Ndepend
•Lattix
•structure101
•Visual Studio
•DeepEnds
•NsDepCop
Copyright © 2016 by Zeb Mason
Tools
•NDepend
•Lattix
•structure101
•Visual Studio
•DeepEnds
•NsDepCop
Copyright © 2016 by Zeb Mason
Visual Studio 2015
$2999 p.a.
Copyright © 2016 by Zeb Mason
Visual Studio 2015
$2999 p.a.
Copyright © 2016 by Zeb Mason
Visual Studio 2015
$2999 p.a.
•Create digraphs in Enterprise
•Save as a DGML file
•Open in Community or Professional
Copyright © 2016 by Zeb Mason
Tools
•NDepend
•Lattix
•structure101
•Visual Studio
•DeepEnds
•NsDepCop
Copyright © 2016 by Zeb Mason
Tools
•NDepend
•Lattix
•structure101
•Visual Studio
•DeepEnds
•NsDepCop
• Visual Studio extension
• Listed on Visual Studio gallery
• Input
• csproj files
• parsed by Roslyn
• .NET assemblies
• decompiled by Mono.Cecil
• vcxproj.filter files
• Output
• DGML file
• Structured by namespace or filter
• Nodes hyperlink to source code files
• HTML report
• Cyclomatic number
• Underlying dependencies
Copyright © 2016 by Zeb Mason
Tools
•NDepend
•Lattix
•structure101
•Visual Studio
•DeepEnds
•NsDepCop
• Visual Studio extension
• Listed on Visual Studio gallery
• Input
• csproj files
• parsed by Roslyn
• .NET assemblies
• decompiled by Mono.Cecil
• vcxproj.filter files
• Output
• DGML file
• Structured by namespace or filter
• Nodes hyperlink to source code files
• HTML report
• Cyclomatic number
• Underlying dependencies
Copyright © 2016 by Zeb Mason
Tools
•NDepend
•Lattix
•structure101
•Visual Studio
•DeepEnds
•NsDepCop
• Visual Studio extension
• Listed on Visual Studio gallery
• Input
• csproj files
• parsed by Roslyn
• .NET assemblies
• decompiled by Mono.Cecil
• vcxproj.filter files
• Output
• DGML file
• Structured by namespace or filter
• Nodes hyperlink to source code files
• HTML report
• Cyclomatic number
• Underlying dependencies
Copyright © 2016 by Zeb Mason
A DGML file - inside Mono.Cecil
Copyright © 2016 by Zeb Mason
Expand Mono.CompilerServices
Copyright © 2016 by Zeb Mason
Expand Mono.CompilerServices.SymbolWriter
Copyright © 2016 by Zeb Mason
A cycle is spotted
Copyright © 2016 by Zeb Mason
Why the cycle?
Copyright © 2016 by Zeb Mason
Concrete class inherits interface
namespace Mono.CompilerServices.SymbolWriter
{
public class CompileUnitEntry : ICompileUnit
{
}
}
Copyright © 2016 by Zeb Mason
Interface returns concrete class!
namespace Mono.CompilerServices.SymbolWriter
{
public class CompileUnitEntry : ICompileUnit
{
}
public interface ICompileUnit
{
CompileUnitEntry Entry {
get;
}
}
}
Copyright © 2016 by Zeb Mason
Underlying dependencies
Copyright © 2016 by Zeb Mason
Summary of metrics
Copyright © 2016 by Zeb Mason
The effect of time and refactoring
Copyright © 2016 by Zeb Mason
Tools
•NDepend
•Lattix
•structure101
•Visual Studio
•DeepEnds
•NsDepCop
Copyright © 2016 by Zeb Mason
NsDepCop
• Some dependency analysis tools enforce design intent by rules
• i.e. one component cannot depend on another
• e.g. NsDepCop rules on namespace dependencies
• These rules can be run automatically
• e.g. NsDepCop is run by MSBuild
• Rule violations can be acted upon
Copyright © 2016 by Zeb Mason
The End
• Related articles on CodeProject
• As-Is Software Architecture
• Dive into Architecture with DeepEnds
• Source on GitHub
• zebmason/itdepends
• zebmason/netdepends
• Extension on Visual Studio gallery
• DeepEnds
Copyright © 2016 by Zeb Mason

Inside architecture

Editor's Notes

  • #2 Image: My holiday snap from 2016
  • #3 Image: My holiday snap from 2016
  • #4 Image: My holiday snap from 2016
  • #5 Image: My holiday snap from 2016
  • #6 Image: My holiday snap from 2016
  • #7 Image: My holiday snap from 2016
  • #8 Image: My holiday snap from 2016
  • #9 Image: My holiday snap from 2016
  • #10 Image: My holiday snap from 2016
  • #11 Image: My holiday snap from 2016
  • #12 Image: http://www.spirit-animals.com/wp-content/uploads/2013/11/Beetle-Flightless-Dung-x-200x134.jpg
  • #13 Image: http://www.spirit-animals.com/wp-content/uploads/2013/11/Beetle-Flightless-Dung-x-200x134.jpg https://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Re-Horakhty.svg/2000px-Re-Horakhty.svg.png
  • #14 Image: http://www.spirit-animals.com/wp-content/uploads/2013/11/Beetle-Flightless-Dung-x-200x134.jpg https://upload.wikimedia.org/wikipedia/commons/thumb/5/55/Question_Mark.svg/2000px-Question_Mark.svg.png
  • #15 Image: http://www.spirit-animals.com/wp-content/uploads/2013/11/Beetle-Flightless-Dung-x-200x134.jpg https://upload.wikimedia.org/wikipedia/commons/thumb/8/8d/Moon_alphabet_Exclamation_mark.svg/1024px-Moon_alphabet_Exclamation_mark.svg.png
  • #20 Image: http://www.galcho.com/Blog/content/binary/WindowsLiveWriter/fd2ae95312ea.NETLayerCake_1219C/dotNet4_thumb.png
  • #21 Image: http://www.galcho.com/Blog/content/binary/WindowsLiveWriter/fd2ae95312ea.NETLayerCake_1219C/dotNet4_thumb.png
  • #22 Image: http://www.galcho.com/Blog/content/binary/WindowsLiveWriter/fd2ae95312ea.NETLayerCake_1219C/dotNet4_thumb.png
  • #23 Image: http://www.galcho.com/Blog/content/binary/WindowsLiveWriter/fd2ae95312ea.NETLayerCake_1219C/dotNet4_thumb.png
  • #24 Image: http://www.galcho.com/Blog/content/binary/WindowsLiveWriter/fd2ae95312ea.NETLayerCake_1219C/dotNet4_thumb.png
  • #25 Image: http://www.galcho.com/Blog/content/binary/WindowsLiveWriter/fd2ae95312ea.NETLayerCake_1219C/dotNet4_thumb.png
  • #27 By Jakob Emanuel Handmann - 2. Kunstmuseum Basel1. digitized version, the source (scanner) of the digitized image is unknown.The image was transferred from en.wiki (en:Image:Leonhard Euler.jpg) under the {{PD-old}} license tag. Wars 16:56, 25 June 2006 (UTC), Public Domain, https://commons.wikimedia.org/w/index.php?curid=893656
  • #28 By Jakob Emanuel Handmann - 2. Kunstmuseum Basel1. digitized version, the source (scanner) of the digitized image is unknown.The image was transferred from en.wiki (en:Image:Leonhard Euler.jpg) under the {{PD-old}} license tag. Wars 16:56, 25 June 2006 (UTC), Public Domain, https://commons.wikimedia.org/w/index.php?curid=893656 By Bogdan Giuşcă - Public domain (PD), based on the image, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=112920
  • #29 By Jakob Emanuel Handmann - 2. Kunstmuseum Basel1. digitized version, the source (scanner) of the digitized image is unknown.The image was transferred from en.wiki (en:Image:Leonhard Euler.jpg) under the {{PD-old}} license tag. Wars 16:56, 25 June 2006 (UTC), Public Domain, https://commons.wikimedia.org/w/index.php?curid=893656 By Bogdan Giuşcă - Public domain (PD), based on the image, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=112920
  • #34 By Christian Albrecht Jensen - http://archiv.bbaw.de/archiv/archivbestaende/abteilung-sammlungen/gesamtbestand-des-kunstbesitzes/gelehrtengemaelde/gelehrtengemalde-seiten/ZIMM-0001.html, Public Domain, https://commons.wikimedia.org/w/index.php?curid=6886354
  • #35 By Christian Albrecht Jensen - http://archiv.bbaw.de/archiv/archivbestaende/abteilung-sammlungen/gesamtbestand-des-kunstbesitzes/gelehrtengemaelde/gelehrtengemalde-seiten/ZIMM-0001.html, Public Domain, https://commons.wikimedia.org/w/index.php?curid=6886354
  • #36 By Christian Albrecht Jensen - http://archiv.bbaw.de/archiv/archivbestaende/abteilung-sammlungen/gesamtbestand-des-kunstbesitzes/gelehrtengemaelde/gelehrtengemalde-seiten/ZIMM-0001.html, Public Domain, https://commons.wikimedia.org/w/index.php?curid=6886354
  • #37 By Christian Albrecht Jensen - http://archiv.bbaw.de/archiv/archivbestaende/abteilung-sammlungen/gesamtbestand-des-kunstbesitzes/gelehrtengemaelde/gelehrtengemalde-seiten/ZIMM-0001.html, Public Domain, https://commons.wikimedia.org/w/index.php?curid=6886354
  • #38 By Christian Albrecht Jensen - http://archiv.bbaw.de/archiv/archivbestaende/abteilung-sammlungen/gesamtbestand-des-kunstbesitzes/gelehrtengemaelde/gelehrtengemalde-seiten/ZIMM-0001.html, Public Domain, https://commons.wikimedia.org/w/index.php?curid=6886354
  • #39 By Christian Albrecht Jensen - http://archiv.bbaw.de/archiv/archivbestaende/abteilung-sammlungen/gesamtbestand-des-kunstbesitzes/gelehrtengemaelde/gelehrtengemalde-seiten/ZIMM-0001.html, Public Domain, https://commons.wikimedia.org/w/index.php?curid=6886354
  • #40 By Christian Albrecht Jensen - http://archiv.bbaw.de/archiv/archivbestaende/abteilung-sammlungen/gesamtbestand-des-kunstbesitzes/gelehrtengemaelde/gelehrtengemalde-seiten/ZIMM-0001.html, Public Domain, https://commons.wikimedia.org/w/index.php?curid=6886354
  • #41 By Christian Albrecht Jensen - http://archiv.bbaw.de/archiv/archivbestaende/abteilung-sammlungen/gesamtbestand-des-kunstbesitzes/gelehrtengemaelde/gelehrtengemalde-seiten/ZIMM-0001.html, Public Domain, https://commons.wikimedia.org/w/index.php?curid=6886354
  • #42 By Christian Albrecht Jensen - http://archiv.bbaw.de/archiv/archivbestaende/abteilung-sammlungen/gesamtbestand-des-kunstbesitzes/gelehrtengemaelde/gelehrtengemalde-seiten/ZIMM-0001.html, Public Domain, https://commons.wikimedia.org/w/index.php?curid=6886354
  • #66 Mono.Cecil depends on two items
  • #67 Select the namespace Mono.CompilerServices
  • #68 Just another namespace
  • #69 Just another namespace