tags : General Programming



Open close

  • These things are not strictly followed, eg. factory pattern breaks open/close of solid but we okay w it

Dependency Inversion Principle

high level module (domain) and the lower level module (implementation detail), both depends on an abstraction.


Architecture Styles

Design Patterns

  • Architectural patterns/Application architecture is superset of design patterns
  • Design patterns divided into 3 basic subcats

Behavioral patters

Structural patterns

Creation-al patters

Concurrency patterns

Performance patterns

  • AoS vs SoA

UI patterns


  • Model represents state
  • View (eg. HTML) generated via Controller
  • Users interact w Model via “actions” on Controller via View
  • Controller never handles app/domain logic. If it has to modify something, it’ll delegate to services/domain objects responsible for manipulating the model.
  • Controllers calling other controllers is code smell.


Application Architecture

  • DDD, Hexagonal, Onion, Clean, CQRS, … How I put it all together
  • Different application architectures try to help us write more maintainable, scalable code etc, helps us follow principles like SOLID, YGNI, DRY, DDD etc etc.
  • They have one thing in common, build layers from high to low, and structure it so that higher levels don’t need to know about lower levels. They have different tradeoffs, some will make your application more complex for compliance with principles etc. In practice, you may end up using several together.


  • Dividing the application into several levels (or tiers), each one taking care of a separate responsibility.
  • Tiers on the bottom can “talk” to upper tiers but not vice versa.
  • 3 tiers (common)
    1. Presentation (top)
      • MVC can be applied to this tier.
      • Eg. user{firstname,lastname}, userview{fullname} Here userview is a model specifically made for MVC. So that we don’t make presentation logic into rest of the application.
      • Having this as a separate layer helps us be flexible w presentation layer. API, Desktop app, Web etc etc.
    2. Logic/Business/Domain/Service
    3. Persistence

Hexagonal (Ports & Adapters)

  • Main idea
    • Separates: Domain and Implementation
    • Externalize dependencies instead of building around them.
    • Declares interfaces, leave implementation out of core
    • Interfaces are ports, implementations are different adapters.

Domain Logic

  • Glues everything together. “use cases” live here.
  • Does not care if output goes to a terminal or to a Web page
  • Does not care if data is stored in a SQL database or a KV store.

Ports & Adapters

Sometimes ppl differentiate adapters into Driving and Driven adapters.

Clean and Onion architectures?

  • They are more or less the same as Port & Adapter architecture. w different nomenclature and depth to the idea according to DDD principles.

How is this applied?

  • Application architecture can be applied at different levels. structures, namespaces, modules, packages etc etc.


  • Loop Unrolling: Technique that attempts to optimize a program’s execution speed at the expense of its binary size. It increase a program’s speed by reducing or eliminating instructions that control the loop. Duff’s device is a way of manually implementing loop unrolling.
  • Abstraction : Abstract away the implementation details and provide a familiar/simplified interface.
  • http://wiki.c2.com/?LawOfDemeter=