notesv2
notesv2
• Composition • Domain
Architecture vs Design
Quality Tatctics Metrics
@ sharding
@ caching
@ parallel
@ lazy loading
@ polling
System Quality
Collect Choose
Quality
Tactics/ Approach
Requirements
(Architecture)
Knows
Technology
Domain
Architectural patterns
Principles
Architectural Anti patterns
Reference Architecture
Code Maintainability
Understand Create
Requirements Code Skeleton
(Design)
Knows
Technology Code Design
Domain Low level design
proc, OO, fun Module Design
OO Design patterns Class Design
Fun Design patterns Implementation Design
Design Principles
Design Anti patterns
Proc vs OO
Proc OO Fun
Performance - - +++
Language C, py, js, java py, java, js Scala, py, js, java
Security - - -
Time to develop ++ -- +
Manage code
--- +++ +
complexity
Quality Approach
• Availability • Caching
• Scalability • GC
• Portability • Doc
• Usability • Transaction
• Interoperability •
Procedural Prog OO Prog
(tree)
(Lego)
P1 classA
Invoice Kst
O CO
P2 P3 classC
Kst
classB O C
Invoice C
O
P4 P5 P6
Cst
classD classE Gst
O
O
Functional Prog OO Prog
(Lego)
(Lego)
C F
C F
F
C
F CO
O
C O C
F
C
F O
C C
F O
C
F
O
New New
New New New New
New
New New New
New
New New
O
New
New C
New O
New
O
New
Procedural Prog Functional Prog
(Lego)
(tree) C F
C F
F
P1 classA
C
F
P2 P3 classC
C
classB F
F
C C
F
P4 P5 P6
C
F
classD classE
(top down)
Abstraction
• Bird Interface
• Eat
fun(Bird bird){
• Hunt bird.fly();
}
•
Good
• DIP
• SRP (***)
• Program. To an Interface (upcast)
• Fun (Max : fit screen, good: 6
• LSP lines)
Business layer
Bad
• Swiss knife (Util, Helper, Service, …)
• Tight coupling
• * to *
• Static Methods
• Bi directional /cyclic
• Overloading family of
• God Class (Controller, Handler, Orchestrator, Interceptor, ..) class
• Flag (proc)
• Magic numbers
• Functional Interface
• Type check
no of interface depends on no of flags
# exception 2
Only Logic
Data change
change
# DI
# Interface typing # Factory
# duck typing @ class factory # gc
Approach @ abstract factory # virtual destructor
# Lamda
@ creator method
@ factory method
# Reflection # Reflection
Extreme
# Adapter
Account Dialog
SA CA SADialog CADialog
<config>
<class>CA</class>
<method>fun</method>
</config>
Tight coupling Interface typing (java) Duck typing (py, js) Lamda (py,js, java)
interface IA{
void f1();
class CA }
{
class CA{ class CA{
void f1(){ class CA implements IA
void f1(){ void f1(){
… {
… …
} void f1(){
} }
} …
} }
}
}
Set(IA obj){
CA obj = new CA( ); IA obj = Factory.create();
obj.fun();
Obj.fun() obj.fun();
}
void fun(int i)
• Flow control Flag => polymorphism {
if(i <2){
….
• Error flag => exceptions }
else{
….
}
}
Boundary
(technology)
Db UI
logic1()
Single Dispatching
? logic2()
# Interface, visitor
logic3()
logic1()
Account Dialog ? logic2() Dual Dispatching
logic3() # Same family : lookup
# Different family : Visitor
logic1()
? logic2() Multi Dispatching
logic3() # Lookup
Single dispatch - virtual fun
class CA{
void fun(){ //1
….
}
}
Performance - - ++
Security - - -
Time to develop/
++ -- +
cost
Learning Curve ++ -- -
Single class,
Object per Path
Single class,
Object per Path
Single dispatch
dual dispatch multi dispatch
Interface / duck
Decision Table
Approach 3
Principles
• SRP (***) • DRY (*)
• LSP • DIP
• Type Check
• Down casting
• Over loading family
of classes
• Arrow code
• Bi directional coupling
• * to * coupling
Inheritance Ref
Lazy Load
No Yes
Parent
• Security
• Transaction
• Persistence
SOC
•
Boundary (technology) logic
UI Control
File
Rest Db
Api Domain logic (Entity)
Rest
Message Api
Api
Boundary (technology logic)
Aggregates Aggregates
Aggregates
Root, Entities, VO
API Boundary
Control
Domain
Dao Boundary
API Boundary
Domain
Dao Boundary
Aggregate Root (DDD)
Invoice
-> LineItem
-> Address
Conditions
Class,
Instance per Path
3.1 Coarse Grained
Interface
Functional Interface 3.2
Interface, Function
Implementation per path Object
Manage
Cyclomatic complexity
Single class,
Object per Path
Single dispatch
dual dispatch multi dispatch
Interface / duck
Decision Table
Builder
1 to * Multiple Cyclic
Multiple Dependancy
Dependancy
Exception handling
UI If sal > 5000 If res == false Things which do not
Caching
Database Change together
Log
File Transaction
API Authorization
EMail
Messaging
Boundary Control
Decorator Rule Engine
Entity
Pipes Filter
Proc OO Fun
(tree) (lego)
Performance - - ++
Security - - -
Learning Curve ++ -- -
Development Time ++ -- +
Unit Test -- + ++
Code Maintainability/
-- ++ +
Support Time
Change behaviour
Change Part of behaviour
Rename behaviour
Enrich behaviour
Add behaviour
CA CA CA CA CA
B1 B1 B1 B1
Client B1
B2 B2 B2 B2 B2
*
CW CA
C1 B1
Client C2 B2
Adapter
Authentication
Autorization
CW CA Audit
B1 Cache
B1
Client B2 Exception Handling
B2
Lazy loading
Simplify network call
Proxy
CW CW CW CW CA
B1 B1 B1 B1
Client B1
B2 B2 B2 B2 B2
Exception Handling
(Exception per error)
Only Data changes Logic changes
In Paths In Paths
switch(flag)
{
Breaks SRP
Case 1:
Data1 P6
Delegated
Case 2: Interface P21
data2 switch(flag)
Case 3: {
Data3 Case 1:
} Logic1 amount * 0.5;
Case 2:
Logic2 (amount - 5000) * 0.08;
Case 3:
Logic3
}
Method
Instantiation Deallocation
Call
Di
Interface # constructor GC
#setter
Factory
# Class Factory
Lamda # Abstract Factory Virtual destructor
# factory Method
# creator Method
Duck typing
Adapter
Code segment Data segment Heap Stack
CX vtbl
CA - 1,
void f(CA a) {} //1 CC
void f(CB b) {} //2 CB - 2,
void f(CC c) {} //3 CC - 3 a
CY vtbl
void f(CA a) {} //4
void f(CB b) {} //5
void f(CC c) {} //6
CA - 4,
CB - 5,
CC - 6
void f(CA a) {} //7
void f(CB b) {} //8
CZ
void f(CC c) {} //9 CZ vtbl x
CA - 7, ? vptr
CB - 8, Runtime x.f(a)
CC - 9 x.vptr.vtbl[0](a)
Compile time
• Boundary and Domain logic is mixed
• Cyclomatic Complexity
•
Abstraction
Interface Bird
{
fly()
} Explicit Implicit
Implicit
p= new Parrot()
do(new Parrot()); do(new Parrot());
do(()=>p.flyHigh());
Composition Inheritance
Lamda
<<stratergy>> <<template method>>
w->w->w->w->w->CA
Composition Composition
<<Decorator>> <<COR>>
Interface IX{
void fun();
} Interface IX{
class CA implements IX void fun();
{ }
void fun(){
… logic class CA implements IX
} {
} IX ref;
class wrapper implements IX void fun(){
{ if(cond)
IX ref; … logic //handle
else
void fun(){ ref.fun(); //delegate
… enrich }
ref.fun(); }
… enrich
}
}
CA->CA->CA->CA->CA
w->w->w->w->w->CA
<<Composition>>
Adapter
“change interface
Of Class”
Interface IY{
void fun2();
}
Interface IX{ class Wrapper implements IY
void fun(); {
} CA ref;
class CA implements IX
{ void fun2(){
void fun(){ ref.fun();
… logic }
} }
}
Internal 80%