Nan Wang
The Open/Closed Principle (OCP) “Software entities (classes, modules, functions, etc.) should be open for extension but closed for modification.” [APPP] When the requirements of an application changes, if the application confirms to OCP, we can extend the existing modules with new behaviours to satisfy the changes (Open for extension). Extending the behaviour of the existing modules does not result in changes to the source code of the existing modules (Closed for modification). Other modules that depends on the extended modules are not affected by the extension.
2012-09-24
5 min read
The Abstract Factory pattern is an important building block for Domain Modelling. It hides the complexity of creating a domain object from the caller of the factory. It also enables us to create domain objects those have complex dependencies without worrying about when and how to inject its dependencies. It is easier to explain the idea with a concrete example. I used to work on a project to build a simple online booking system for a heath club.
2012-09-05
6 min read
Data Access Object (DAO) is a commonly used pattern to persist domain objects into a database. The most common form of a DAO pattern is a class that contains CRUD methods for a particular domain entity type. Assumes that I have a domain entity class “Account”: package com.thinkinginobjects.domainobject; public class Account { private String userName; private String firstName; private String lastName; private String email; private int age; public boolean hasUseName(String desiredUserName) { return this.userName.equals(desiredUserName); } public boolean ageBetween(int minAge, int maxAge) { return age >= minAge && age <= maxAge; } } Follow the common DAO approach, I create a DAO interface:
2012-08-26
7 min read