Layered Architectural Design Patterns

Layered patterns which focus on separating designs into distinct areas of concern to group classes and components toghether.

There are specific rules to which we should stick to when working with Layers.

  • A Layer is only allow to communicate with layers immediately above or below.
  • All the layers should follow the same architecture design, different design patterns should not be mixed in the same layer.
  • All the elements of the layer should be semantically related.
  • If there is a components to which all the layers need to have access they should access to a global component.

Client/Server Pattern

  • Distinct client and server
  • Separated by network
  • Communication protocol
  • Many clients, one server
ProsCons
SecureRequires Network
Simple CommunicationDifficult to scale out
Centralized controlSingle Point of failure
Easy to manageHard to debug

Layered Pattern

Lowe layers need to be super flexible because they will serve to upper layers.

  • Strict areas of concern
  • Communication is only to immediate neighbors.
ProsCons
High isolationCan hide complexity
High abstractionDeep call chains
Structured CommunicationMay harm performance
Easy to scale outLowest layer must cover all use cases

N-Tier Architecture

Similar to Layered Pattern but each of them is deployed onto different machines.

  • Layers deployed to servers
  • Usually 3 Tiers
  • Communication between layers uses network
ProsCons
High abstractionNetwork = Point of failure
High isolationNetwork may be slow
Structured communicationCoarse interfaces
Easy to scale outHard to debug

Logical Layered Design

Layering Strategy

Define Layer Interfaces

Alternatives: Singletons, Command Pattern, Dependency Injection, Message-based,…

@Mark Farragher