6. “架构”名词的来源
最初起源于建筑领域:
Architecture is both the
process and product of
planning, designing, and
construction, usually of
buildings and other
physical structures.
Architectural works, in the
material form of buildings,
are often perceived as
cultural symbols and as
works of art.
后被引用到IT领域
15. 架构师职业成长路径(二)
往哪儿去?
参考《Career Development for Architects》,Kevin Francis
Delivery
Manager, etc
Infrastructure
Manager, etc
CTOCIO Other Executive
Infrastructu
re Manager
SOA
Architect
Snr Data
Architect
Snr
Project
Manager
Solution
Architect
Enterprise Architect or Consultant
104. The Release Reuse Equivalency Principle(REP)
The granule of reuse is the granule of release(软件包的粒度与可重用的粒度保持一致)
The Common Closure Principle(CCP)
Classes that change together, belong together(一致变化的类,应该属于同一个包)
The Common Reuse Principle(CRP)
Classes that aren’t reused together should not be grouped together(不被一起重用的类,
不放到一个包里)
高内聚(Cohesion)
面向服务/组件的系统架构设计过程
105. The Acyclic Dependencies Principle(ADP)
The dependencies between packages must not form cycles(软件包之间不能相互依赖,构
成依赖循环)
The Stable Dependencies Principle(SDP)
Depend in the direction of stability(包之间的依赖关系都应该是稳定方向依赖的,包要依赖的
包要比自己更具稳定性)
The Stable Abstractions Principle(SAP)
Stable packages should be abstract packages(稳定的包,应该是抽象的包,以此带来可变
性)
低耦合(Coupling)
面向服务/组件的系统架构设计过程
112. (5)CQRS架构风格
Betrand Meyer(Eiffel语言之父,开-闭原则OCP提出者)在Object Oriented Software
Construction一书中提到一种命令查询分离(Command Query Separation, CQS)的
概念。
Separation of
functions that write
&
functions that read
Functions that write are called Command
methods and must not return a value
Functions that read are called Query
methods and must have no side effects
117. 寻找事件源(Event Sourcing):聚合根
Aggregates track their own Domain Events
and derive state from them
OrderCreated ProductAdded ProductAdded ProductRemoved ProductAdded OrderShipped
October
5
October
6
October
6
October
7
October
7
October
9
CQRS事件源
118. FULL CQRS with Event Sourcing:
UI Domain
Event
Store
Commands – Change data
Commands Events
SQL DB Document DB Graph DB
UI Data
Queries – Ask for data
Events
Query Build
Our single source
of truth
CQRS事件源(续)
119. FULL CQRS with Event Sourcing代码实现案例:
public class CustomerCommandHandler {
private Repository<Customer> customerRepository;
public CustomerCommandHandler(Repository<Customer> customerRepository) {
this.customerRepository = customerRepository;
}
@CommandHandler
public void handle(UnsignCustomer cmd) {
Customer customer = repository.load(cmd.getCustomerId());
customer.unsign();
}
}
public class Customer {
private boolean signedUp;
public void unsign() {
if (signedUp) {
apply(new CustomerUnsignedEvent());
}
}
@EventHandler
private void handle(CustomerUnsignedEvent event) {
signedUp = false;
}
}
CQRS代码实现案例
120. Sales
Product
SKU
Name
Price
Quantity Ordered
…
Inventory Service (SAP)
Product
SKU
QOH
Location Code
…
Pricing Service
Product
SKU
Unit Price
Promotional Price
…
Inventory
Pricing
Sales
Customers
New SKU
Event
New SKU
Event
New SKU
Event
Order
AcceptedE
vent
MessageBus
Who coordinates
the sales process?
Online Ordering System
Web Shop
(Composite UI)
CQRS应用示例
121. 扩展新的应用功能:
Sales Service
Order
Accepted
Billing Service
Shipping
Process Manager
(Saga)
Shipping Service
Online Ordering System
MessageBus
Order
Accepted
Order
Accepted
Customer
Billed
Customer
Billed
Ship
Order
Ship
Order
CQRS应用示例(续)
158. 举例
你是一个ATM机软件的开发工程师,需要测试ATM软件的存取款功能,但在测
试时不想产生实际的银行业务,该怎么办呢?
public class ATMGui{
……
private Status doWithdrawal(Account account, float amount) {
Transaction transaction = new Transaction();
transaction.setSourceAccount(account);
transaction.setDestAccount(myCashAccount());
transaction.setAmount(amount);
transaction.process();
if (transaction.successful()) {
dispense(amount);
}
return transaction.getStatus();
}
}
Public class ATMGuiTest{
… …
public void testCheckingWithdrawal() {
float startingBalance = balanceForTestCheckingAccount();
AtmGui atm = new AtmGui();
insertCardAndInputPin(atm);
atm.pressButton("Withdraw");
atm.pressButton("Checking");
atm.pressButtons("1", "0", "0", "0", "0");
assertContains("$100.00", atm.getDisplayContents());
atm.pressButton("Continue");
assertEquals(startingBalance - 100,
balanceForTestCheckingAccount());
}
}
Factory Method模式
159. class Class Model
EA 9.0 Unregistered Trial Version EA 9.0 Unregistered Trial Version EA 9.0 Unregistered Trial Version
EA 9.0 Unregistered Trial Version EA 9.0 Unregistered Trial Version EA 9.0 Unregistered Trial Version
EA 9.0 Unregistered Trial Version EA 9.0 Unregistered Trial Version EA 9.0 Unregistered Trial Version
EA 9.0 Unregistered Trial Version EA 9.0 Unregistered Trial Version EA 9.0 Unregistered Trial Version
EA 9.0 Unregistered Trial Version EA 9.0 Unregistered Trial Version EA 9.0 Unregistered Trial Version
EA 9.0 Unregistered Trial Version EA 9.0 Unregistered Trial Version EA 9.0 Unregistered Trial Version
EA 9.0 Unregistered Trial Version EA 9.0 Unregistered Trial Version EA 9.0 Unregistered Trial Version
EA 9.0 Unregistered Trial Version EA 9.0 Unregistered Trial Version EA 9.0 Unregistered Trial Version
EA 9.0 Unregistered Trial Version EA 9.0 Unregistered Trial Version EA 9.0 Unregistered Trial Version
EA 9.0 Unregistered Trial Version EA 9.0 Unregistered Trial Version EA 9.0 Unregistered Trial Version
EA 9.0 Unregistered Trial Version EA 9.0 Unregistered Trial Version EA 9.0 Unregistered Trial Version
ATMGui
+ doWithdrawal() :void
+ createTransaction() :void
MockedATMGui
+ createTransaction() :void
ConcreteATMGui
+ createTransaction() :void
ATMGuiTest
+ testCheckingWithdrawal() :void Transaction transaction =
createTransactioin();
......
return new MockedTransaction(); return new RealTransactioin();
ATMGui gui = new MockedATMGui();
......
Factory Method模式