+ All Categories
Home > Documents > The benefits of architecture How to create architecture...

The benefits of architecture How to create architecture...

Date post: 25-Oct-2020
Category:
Upload: others
View: 3 times
Download: 0 times
Share this document with a friend
46
Agenda What is architecture The benefits of architecture How to create architecture
Transcript
Page 1: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Agenda● What is architecture● The benefits of architecture● How to create architecture

Page 2: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

What is architecture● The shape of the system● Involves all levels

Page 3: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

The benefits of architecture● Behaviour and structure● Reduce amount of work and improve efficiency● Support development, deployment, maintenance

Page 4: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Development● A system that is difficult to develop has a short lifespan● Small teams can do without good architecture● Large systems need good architecture

Page 5: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Deployment● Deployment should be as easy as possible● Can be difficult with a microservice architecture

Page 6: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Maintenance● Should be easy to find where to make changes● And to make them safely

Page 7: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

How to create architecture● SOLID principles● Component principles● Independence● The clean architecture

Page 8: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Single responsibility principle● A module should only have one reason to change

BetOffer+price()+report()+tweet()

Reporting tool

Trader

Social marketing

Page 9: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

● A module should only have one reason to change● Can be solved by separating data and functionality

Single responsibility principle

BetOfferData Reporting tool

Trader

Social marketing

TraderTool

BetOfferReporter

MarketingService

Page 10: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Open closed principle● Open for extension, closed for modification● Requirement changes should not necessitate code changes

Page 11: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Example: Reporting settlement information

SettlementController

SettlementRequest

SettlementResponseAuditReporter

SettlementClient <I> HttpClient

Page 12: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Example: Reporting settlement information

SettlementController

SettlementRequest

SettlementResponseReporter <I>

OperatorReporter

AuditReporter

SettlementClient <I> HttpClient

Page 13: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Liskov substitution principle● Subtypes should be substitutable

Event <I>+getParticipants()

Match+getParticipants()

Competition+getParticipants()

Page 14: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Example: LSP violation● A service that reports payouts for customers’ punters:

/punter/123/payout● But one customer use a different path: /payout/punter/123● Violation leads to a lot of more work if we want a clean solution

Page 15: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Interface segregation principle● Large interfaces forces users to depend in things they don’t need

Trader Reporting tool

Social marketer

BetOffer <I>+price()+report()+tweet()

Page 16: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Interface segregation principle● Large interfaces forces users to depend in things they don’t need

Trader Reporting tool Social marketer

ThreeWay+price()+report()+tweet()

BetOffer <I>+price()

Reportable <I>+report()

Tweetable <I>+tweet()

Page 17: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Interface segregation principle● Large interfaces forces users to depend in things they don’t need

public void settleThreeWay(final int winningOutcome) { settlementSender.send(new Settlement() {

@Override public int getWinningOutcome() { return winningOutcome; }});

}

Page 18: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Interface segregation principle● Large interfaces forces users to depend in things they don’t need

public void settleThreeWay(final int winningOutcome) { settlementSender.send(new Settlement() {

@Override public int getWinningOutcome() { return winningOutcome; }@Override public int getCompetitionId() { return -1; } // not a competition @Override public String getReport() { return “Default report”; } @Override public String getTweet() { return “I’m a settlement!”; }@Override public void onSettled() { /* don’t care */ }

});}

Page 19: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Dependency inversion principle● Want to separate business logic from database, UI, etc.● Higher levels need to call lower levels● Invert the dependency using an interface

Page 20: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Dependency inversion principle● Want to separate business logic from database, UI, etc.● Higher levels need to call lower levels● Invert the dependency using an interface

BetService HttpClient+registerBet()Before:

Page 21: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Dependency inversion principle● Want to separate business logic from database, UI, etc.● Higher levels need to call lower levels● Invert the dependency using an interface

BetService HttpClient+registerBet()Before:

After: BetService HttpClient+registerBet()

AdmClient <I>+registerBet()

Page 22: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Component principles● SOLID for components● Component cohesion● Component coupling

Module - a set of related functionality, a class, a package, a jar

Component - the smallest entity that can be deployed, a jar

Page 23: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Component cohesion● Reuse/release equivalence principle● Common closure principle● Common reuse principle

Page 24: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

● Modules in a component should make sense to be released together○ They have a common theme○ They should be reusable

● Kambi-commons○ The modules have something to do with Kambi○ Should not include NiroTwitterClient because it’s not reusable

Reuse/release equivalence principle

Page 25: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Common closure principle● Gather modules which change at the same time and for the same reasons● When requirements change, changes are restricted to a single component● Kambi-commons

○ CustomerEnum is changed for the same reason and rate as ExtApiEndpointContext ○ CustomerEnum is changed for a different reason and rate than TennisSet

Page 26: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Common reuse principle● Don’t force the user to depend on things it doesn’t need● A user should need to depend on all modules in a component● Kambi-commons

○ If you need monitoring, you’ll probably use all classes in the monitoring package○ But you might not want to be forced to depend on TwitterMonitorAdapter

Page 27: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Component cohesion

Reuse/release principle

Common reuse principle

Common closure principle

Redundant releases

Not reusableToo many components change

Page 28: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Component coupling● Acyclic dependencies principle● Stable dependencies principle● Stable abstractions principle

Page 29: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Acyclic dependencies principle● Don’t want dependency cycles

Page 30: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Acyclic dependencies principle● Don’t want dependency cycles● If a cycle is formed, we’ve got trouble

Page 31: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Acyclic dependencies principle● Cycles can be broken using Dependency inversion principle

BetOfferService

HttpClient

Page 32: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Acyclic dependencies principle● User depends on an abstraction

BetOfferService

AdmClient <I>

HttpClient

Page 33: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Acyclic dependencies principle● Can extract the dependency into a new component

Http Client

Page 34: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Stable dependencies principle● Always depend on things that are more stable than yourself

Page 35: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

● Something is stable if many things depend on it

Defining stability

Page 36: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Defining stability● Something is unstable if it depends on many things

Page 37: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Stable abstractions principle● A component should be as abstract as it is stable● How can a stable component be flexible enough to handle changes?● SDP says that dependencies should be in the direction of stability● SAP says that stability is abstraction● So dependencies should point to abstractions

Page 38: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Abstractness vs. Instability● Abstractness = (# abstract classes) / (# classes)● Instability = Fan out / (Fan out + Fan in)

Abstractness

Instability (1, 0)

(0, 1)

Page 39: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Abstractness vs. Instability● (0, 0) is difficult to extend and modify● (1, 1) is useless● Want components that are pure: (0, 1) and (1, 0)

Abstractness

Instability (1, 0)

(0, 1)

Page 40: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Independence● Use cases● Policies● Levels

Page 41: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Use cases● A use case is a description of how the system is used● To support use cases is the architecture's highest priority● If it’s a shopping cart, the architecture should show that● Finding each use case should be easy

Page 42: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Use cases cont.● Use cases may change for various reasons● They are small vertical slices in the system● Want to be able to add use cases without affecting existing ones● Allow for scaling specific use cases (microservices)

Page 43: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

The clean architecture● Common architectures

○ Ports and adapters / Hexagonal○ Data, Context, Interaction○ Boundary, Control, Entity

● Focused on separation of concerns● (Screaming architecture)

Page 44: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

Screaming architecture● Is the architecture screaming health care system or Spring MVC?● The architecture supports the system’s use cases, not frameworks● A good architecture should let all use cases be testable without any

frameworks

Page 45: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

● The source code dependencies point towards the middle

● An inner circle does not know about theouter circle

● Entities embodies the critical business rules● Use cases are the application specific rules● Frameworks are where are the details are

(DB, Web, etc.)● Can of course use more than four circles

The clean architecture

Entities

Use cases

Controllers

Web

Gateways

DB

Page 46: The benefits of architecture How to create architecture Agendacronsioe.asuscomm.com/static/pdf/architecture.pdf · Common closure principle Gather modules which change at the same

End● Not covered

○ Policies○ Levels○ Humble objects○ Boundaries○ Services○ Packaging strategies


Recommended