Work Habits

By Haemoglobin
5/30/2010 (revision 4)

Object Oriented Design

  • UML Cheatsheet
  • Program to an interface, not an implementation.
  • Always remove code duplication.
  • Favour object composition (wrappers) over class inheritance.
  • Always use most restrictive options by default, i.e sealed, non-virtual, private - only open up if maintenance/backwards compatibility ramifications are accepted.
  • Know where to use:
    • Aspect Oriented Programming (example) for cross cutting concerns.
    • Dependency Injection (DI) / Inversion of Control (IoC) architecture (framework list) for testability and pluggable provider patterns.
      • Typically done by sending an interface type to a constructor.
    • Unit testing frameworks such as NUnit.
    • Mock frameworks (such as Moq) to use with unit testing to mock (fake) an object the method you are testing calls (relies on DI object design)
    • Use Design patterns.
    • Consider use of the MS Enterprise Library:
      • Caching Application Block.
      • Cryptography Application Block.
      • Data Access Application Block.
      • Exception Handling Application Block.
      • Logging Application Block.
      • Policy Injection Application Block.
      • Security Application Block.
      • Unity Application Block.
      • Validation Application Block.

Design Principles

Low Coupling

Given two lines of code, A and B, they are coupled when B must change behavior only because A changed.

High Cohesion

  • They are cohesive when a change to A allows B to change so that both add new value.
  • Cohesion is inversely proportional to the number of responsibilities (methods) a module (class) has.

Separation of Concerns

Low coupling and high cohesion can be achieved through separation of concerns, modularity and information hiding / encapsulation.

  • Well defined stable public interfaces with private implementation details.

Comments

Powered by BlogEngine.NET 1.6.1.0 | Design by styleshout | Enhanced by GravityCube.net | 1.4.5 Changes by zembian.com | Adapted by HamishGraham.NET
(c) 2010 Hamish Graham. Banner Image (c) Chris Gin