Patterns of Enterprise Application Architecture – notes


  • Gateway – represent access to some system or resource
  • Registry
  • Value object

Domain logic

  • Transaction script – simple function between request arrived and data persisted
  • Domain model – contains both: behaviour and data
  • Service layer – wraps model with secondary operations like security, logging, etc


  • Table Data gateway – one instance per table – for all rows
  • Row Data gateway – one instance per row
  • ActiveRecord – one per row or view, contains domain logic too
  • Data Mapper – maps between business objects and stored rows

Object relation behaviour

  • Unit of work – contains set of object affect by common operation or transaction to persist them correctly
  • Identity map – keeps any object loaded from database only once
  • Lazy load – loads a data when is really required/used


  • Identity field – uniq identifier of a row
  • Foreign key mapping
  • Association table mapping
  • Embedded value
  • Inheritance models – single table (all classes within the same table), class table (each has own table), concrete table (only concrete classes have own tables)
  • Query object
  • Repository

WEB representational

  • MVC
  • Page controller
  • Front controller
  • Template view
  • Transform view
  • Application controller – dedicated object that manages flow of application usage
  • Distribution patterns
  • Remote facade
  • Data Transfer Object

Concurrent access

  • Optimistic lock – versioning and conflicts handling
  • Pessimistic lock – prevents conflicts
  • Coarse-grained lock
  • Implicit lock

Session – client/server/database


Enterprise Integration Patterns extract


  • Message
  • Message channel
  • Pipes and filters
  • Message routers
  • Message translator
  • Message Endpoint


  • Point-To-Point
  • Publish-Subscribe
  • Datatype channel – for particular type of message
  • Invalid message channel – used if a receiver cant proceed the message obtained
  • Dead letter channel – if a message could not be delivered
  • Guaranteed delivery – persist message on both ends of channel
  • Channel adapter – message endpoint
  • Message bridge – connection between different messaging systems
  • Message bus – message queue


  • Command message – command to execute, invoke a procedure
  • Document message – message with data
  • Event message – message with changed state
  • Request-Replay – two message through two different channels
  • Return Address – message contains a channel for replay
  • Correlation identifier – ID obtained at response message to match the request method sent
  • Message sequence – sequence identifier, position identifier, size or end indicator
  • Message expiration
  • Format indicator


  • Content based router
  • Message filter
  • Dynamic router
  • Splitter+Aggregator
  • Resequencer – reorder a sequence of messages
  • Scatter-Gather
  • Message broker – contain a logic of message flow


  • Envelop
  • Content enricher / filter
  • Normalizer – cast all message to common format


  • Gateway – connects application and messaging system
  • Mapper – maps messages and business objects
  • Poling consumer
  • Competing consumers – a few consumers are listening the same channel, but only one will obtain each message

System management

  • Control Bus – channel that delivers command/controlling messages to all parties to manage their work
  • Detour
  • Wire tape – T-component, to log messages out
  • Message history – message is appended by information of each component passed
  • Message Store – all messages are stored at some database
  • Test message
  • Channel purger

DDD extract

Model and scenarios first before coding, coding just implementation of model, focus on business, not on database or technologies

Model based language

Model description – UML, text, anything

Layered architecture – UI, application, domain, infrastructure

Bounded context – common ubiquitous (with domain experts) language, all terms are uniq in scope of the bounded context, if there are two meaning of the same form – this definitely means that they belong to two different bounded contexts

Ubiquitous language (best implemented by BDD – given/when/then)

There will be design anyway, good (common for everyone, verified by domain experts) or bad (mix of multiple designs from multiple developers)

Context mapping – map of interconnected bound contexts.


  • partnership
  • shared kernel (try to avoid this)
  • customer-supplier
  • anticorruption layer
  • open host service

Entities and value objects – JPA


Aggregate – facade, root object that hides and manipulates underlying set/tree of child objects (entities)

Factory – creates new objects

Repository – stores (persists) already created objects

Services – stateless functions

How to improve the model:

  1. Listen domain experts, their language
  2. Build common language

Event sourcing (storing domain events, that represent changes at model, then calculate the current state when needed by merging these events)