Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Growing Object-Oriented System
Search
Kent Wang
December 10, 2012
Programming
410
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Growing Object-Oriented System
Kent Wang
December 10, 2012
Transcript
110 slides
Growing Object-Oriented System Principles, Guidelines, and Methods Kent Wang Dec
6, 2012
Agenda • Introduction • Understand The Problem • Broad-Brush Design
• Implementation • Recommended Readings
Introduction
Why This Talk
None
Software Developing Is a Learning Process
Feedback is Critical Understand the Problem (Analysis) Broad-Brush Design (Architecture)
Test Driven Development (Implementation) Deployable System
Understand the Problem
Understand The Problem • User Story • Use Case •
Conceptual Model • Color Modeling
User Story Users could pay for their orders from various
platform via tenpay
Use Case User Pay
Use Case Is Valuable But Not The End
Digging A Conceptual Model
Dig Conceptual Model
Dig Conceptual Model Payment
Dig Conceptual Model Payment Partner Trade
Dig Conceptual Model Payment Partner Partner Trade
Dig Conceptual Model Payment Partner User Partner Trade
Dig Conceptual Model Payment Partner User Buyer Seller Partner Trade
Dig Conceptual Model Payment Partner User Payment Type Buyer Seller
Partner Trade
Color Modeling
Color Modeling Moment- Interval
Color Modeling Moment- Interval Party / Place /Thing
Color Modeling Moment- Interval Role Party / Place /Thing
Color Modeling Moment- Interval Role Description Party / Place /Thing
User Story Changed Users could pay for their orders from
various platform via tenpay or alipay
Simple Solution Payment Partner User Payment Type Buyer Seller Partner
Trade
Simple Solution Payment Partner User Payment Type Buyer Seller Partner
Trade
The Missing Concept Payment Partner User Payment Type Buyer Seller
Partner Trade
The Missing Concept Payment Partner User Payment Type Buyer Seller
Partner Trade Provider Payment
The Missing Concept Payment Partner User Payment Type Buyer Seller
Partner Trade Provider Payment Payment Provider
Models Are Not Right Or Wrong They Are More Or
Less Useful
One Team, One Language
Bounded Context Payment Partner Payment Type Provider Payment Payment Provider
Context Map Provider Payment Transaction unipay tenpay
Context Map Provider Payment Transaction unipay tenpay Transaction Map
Get Help If Required
Broad-Brush Design
Broad-Brush Design • Tackling Complexity • Architectural Level • Application
Level • Domain Model Level
Tackling Complexity
Separation of Concerns
Layered Architecture Application Presentation Data Source
Layered Architecture Application Presentation Data Source Domain
High Level of Abstraction
High Level of Abstraction
Architectural Level
Infrastructure • Distributed or Not • Synchronous or Asynchronous •
Data Source
Architectural Style Transaction Script Table Module Domain Model Complexity Tool-Chain
Location of Domain Logic DAO AO vs.
Location of Domain Logic DAO AO Domain vs.
Location of Domain Logic DAO AO Domain vs.
Location of Domain Logic DAO AO Domain vs.
Concurrent Control • Transaction is not Silver Bullet • Optimistic
or Pessimistic • Offline or Not
Application Level
Walking Through Scenarios
Walking Through Scenarios User Submit Payment Save Payment Get Payment
Parameter Submit To Provider
Walking Through Scenarios User Submit Payment Save Payment Get Payment
Parameter Submit To Provider Presentation Layer Application Layer
Intension-Revealing Interface CUnipayAO GetPaymentParameter CUnipayAO ProcessTrade vs.
Do One Thing CUnipayAO GetPaymentParameter
Do One Thing CUnipayAO GetPaymentParameter Save or update Payments Assemble
Payment Parameters
Command Query Separation System Command Query State A
Command Query Separation System Command Query State B
Command Query Separation System Command Query State B
Command Query Separation CUnipayAO GetPaymentParameter SetupPayment Save or update Payments
Assemble Payment Parameters
Module Payment Payment Provider Partner Notification History Security Settlement
Domain Model Level
Simplify Associations Payment Partner User Payment Type Buyer Seller Partner
Trade Provider Payment Payment Provider
Simplify Associations Payment Partner Payment Type Partner Trade Provider Payment
Payment Provider
Simplify Associations Payment Partner Payment Type Provider Payment Payment Provider
1..*
Simplify Associations Payment Partner Payment Type Provider Payment Payment Provider
1 current
Design Is Not Just A Technical Issue
Integrity Problem ChargePlan ChargePlan LineItem ChargePlan LineItem amount = 50
amount = 50 amount = 100
Integrity Problem ChargePlan ChargePlan LineItem ChargePlan LineItem amount = 50
amount = 50 amount = 100 ChargePlan LineItem amount = 50
Aggregate ChargePlan ChargePlan LineItem ChargePlan LineItem amount = 50 amount
= 50 amount = 100
Aggregate ChargePlan ChargePlan LineItem ChargePlan LineItem amount = 50 amount
= 50 amount = 100 ChargePlan LineItem amount = 50
Domain Model Pollution ao_unipay_settle Payment Relay Service ao_unipay Transaction
Anti-Corruption Layer ao_unipay_settle nao_unipay_tenpay Tenpay Service Payment Relay Service ao_unipay
Transaction
Design To Test Tenpay Service Facade
Design To Test Tenpay Service Facade Mock Tenpay Relay Client
Tenpay Service Facade Test
Design To Test Tenpay Service Facade Mock Tenpay Relay Client
Tenpay Service Facade Test 1. RegisterChargePlan(plan) 3. Execute(request, response) 4. Checking Request 5. Return Response 6. Return Response 7. Parse Response 2. Assemble Request 8. Return Result 9. Checking Result
Implementation
Implementation • Design Tools • Make A New Type •
Consistent Abstraction Level • Open Close Principle • Extract Hidden Concept
Costly Tools Don’t Produce Better Designs
UML Without CASE
CRC Card CTenpayProviderType Make Tenpay Trade No Make Tenpay Settle
No Get Request Builder CTenpayTradeNo CTenpayProvider CTenpayRequest Builder
CRC Card CTenpayProviderType Make Tenpay Trade No Make Tenpay Settle
No Get Request Builder CTenpayTradeNo CTenpayProvider CTenpayRequest Builder Class Responsibility Collaborator
Duplicated Code // inside NotifyPayment function // inside GetPayment fuction
if (sProviderTradeNo.length() != 28) { return ERR_APP_PARAM_INVALID; } uint64_t ddwProviderPartnerNo = lexical_cast<uint64_t>(sProviderTradeNo.substr(0, 10)) uint64_t ddwSerialNo = lexical_cast<uint64_t>(sProviderTradeNo.substr(18)); dwRet = GetPaymentByProviderTradeNo( ddwProviderPartnerNo, ddwSerialNo);
Make A New Type CTenpayTradeNo Make Tenpay Trade No Parse
Tenpay Trade No Verify Tenpay Trade No CTenpayProvider Get Date From Trade No Get Serial No From Trade No
Use The New Type // inside NotifyPayment function // inside
GetPayment fuction CTenpayTradeNo oTradeNo; if (!CProviderTradeNo::TryParse(sProviderTradeNo, oTradeNo) { return ERR_APP_PARAM_INVALID; } dwRet = GetPaymentByProviderTradeNo( oTradeNo.GetProviderPartnerNo(), oTradeNo.GetProviderTradeSerialNo());
Too Much Detail // inside SetupPayment function if (dwRet ==
ERR_PAYMENT_NOT_FOUND) { CPayment oPayment; oPayment.SetPaymentId(NextPaymentId()); oPayment.SetAmount(rTrade.GetAmount()); oPayment.SetBuyerUid(rTrade.GetBuyerUid()); oPayment.SetSellerUid(rTrade.GetSellerUid()); // ... 50 lines more oPayment.SetLastUpdateTime(CTime::Now()); dwRet = m_pDao->SavePayment(oPayment); if (dwRet != 0) { // ... 10 lines of error handling } return dwRet; }
Too Much Detail // inside SetupPayment function if (dwRet ==
ERR_PAYMENT_NOT_FOUND) { CPayment oPayment; oPayment.SetPaymentId(NextPaymentId()); oPayment.SetAmount(rTrade.GetAmount()); oPayment.SetBuyerUid(rTrade.GetBuyerUid()); oPayment.SetSellerUid(rTrade.GetSellerUid()); // ... 50 lines more oPayment.SetLastUpdateTime(CTime::Now()); dwRet = m_pDao->SavePayment(oPayment); if (dwRet != 0) { // ... 10 lines of error handling } return dwRet; }
Code Closer To Problem // inside SetupPayment function if (IsPaymentNotExist(dwRet))
{ return CreatePayment(); } else { return MakeSurePriceHasNotChanged(); }
Code Closer To Problem // inside SetupPayment function if (IsPaymentNotExist(dwRet))
{ return CreatePayment(); } else { return MakeSurePriceHasNotChanged(); }
Keep Consistent Abstraction Level
Feature Envy // inside GetPaymentParameter function ... if (rProvider.GetType() ==
TENPAY) { BuildBasicParameter(rPayment); if (rSpec.GetPaymentMethod() == STANDARD) { BuildParameterOfTenpayStandardPayment(rPayment); } else if (rSpec.GetPaymentMethod() == BANK) { BuildParameterOfTenpayBankPayment(rPayment); } } ...
Feature Envy // inside GetPaymentParameter function ... if (rProvider.GetType() ==
TENPAY) { BuildBasicParameter(rPayment); if (rSpec.GetPaymentMethod() == STANDARD) { BuildParameterOfTenpayStandardPayment(rPayment); } else if (rSpec.GetPaymentMethod() == BANK) { BuildParameterOfTenpayBankPayment(rPayment); } } ...
Power Of Values IPaymentRequestBuilder Build Payment Request GetPaymentUrl CopyPaymentParameters CProviderType
CProvider CTenpayStandardPayment RequestBuilder Build Payment Request GetPaymentUrl CopyPaymentParameters CTenpayProviderType CTenpayBankPayment RequestBuilder Build Payment Request GetPaymentUrl CopyPaymentParameters CTenpayProviderType
The Clean Way // inside GetPaymentParameter function ... IPaymentRequestBuilder* pBuilder
= rSpec.GetPaymentMethod(). NewPaymentRequestBuilder(rProvider); pBuilder->Build(rPayment); ...
Open for Extension Close for Modification
Extract Hidden Concept // inside NotifyPayment function ... if (rPayment.GetCurrentProviderPaymentId()
== rProviderPayment.GetProviderPaymentId() && rPayment.IsWaitPay()) { rPayment.Accept(rProviderPayment); } ...
Extract Hidden Concept // inside NotifyPayment function ... if (rPayment.GetCurrentProviderPaymentId()
== rProviderPayment.GetProviderPaymentId() && rPayment.IsWaitPay()) { rPayment.Accept(rProviderPayment); } ...
Extract Hidden Concept Payment ProviderPayment IPaymentAcceptingPolicy *
Extract Hidden Concept // inside NotifyPayment function IPaymentAcceptingPolicy* paymentAcceptingPolicy; ...
if (paymentAcceptingPolicy->IsAllowedToAccept( rPayment, rProviderPayment)) { rPayment.Accept(rProviderPayment); } ...
Extract Hidden Concept // inside NotifyPayment function IPaymentAcceptingPolicy* paymentAcceptingPolicy; ...
if (paymentAcceptingPolicy->IsAllowedToAccept( rPayment, rProviderPayment)) { rPayment.Accept(rProviderPayment); } ...
Making Implicit Concept Explicit
Recommended Readings
None
None
Q & A
Thanks for your time
Other Decks in Programming
See All in Programming
私なりのハーネスエンジニアリング ~独自の言語処理系の開発を通して~
seosoft
0
220
オーケストレーション記述言語 Katari
yukikurage
0
270
AIコーディング時代のKotest ユニットテストから APIレベルの仕様固定化テストへ
ooga04
0
300
느린 네트워크와 저사양 디바이스 사용자를 위한 웹뷰 로딩 시간 개선기
kmkim
1
260
Ruby から Emacs を操作したい
phigasui
0
360
Crash Auto Pipelines
veronikapj
1
440
Goコンパイラを作ってGoをもっと理解する / Build a Go compiler to better understand Go
ikura_hamu
0
130
ローカルLLMの基本と近況 2611 / Local LLM basics and recent situation 2611
kishida
3
600
Vue.jsで作る空間解析アプリとCapacitorプラグインのData Bridge
hal_spidernight
1
180
AIが実装を担う時代の「技術設計」と「チームマネジメント」
kamina_zzz
2
280
社内AIエージェント「Askワンバン」における コストチューニングの取り組み
t0yohei
0
170
AI時代のシニアエンジニアとは
yosuke_furukawa
PRO
15
12k
Featured
See All Featured
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
610
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.8k
A Tale of Four Properties
chriscoyier
163
24k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
Between Models and Reality
mayunak
4
590
Context Engineering - Making Every Token Count
addyosmani
9
1.3k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
680
Technical Leadership for Architectural Decision Making
baasie
4
650
YesSQL, Process and Tooling at Scale
rocio
174
15k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k