Archive

Posts Tagged ‘design’

Implementing Design by Contract

June 14th, 2011 No comments

Design by Contract essentially mean that a class has to fulfill certain responsibilities and are inside a boundary. This is done by use of interface. If you have a class which implements an interface (as is done in Java) , it has been designed by contract. The contract here is the methods which this class has to implement.

Going further down , if a class method getMyDetails(long ssnId)
we can put a assert statement like
assert ssnId != null;

Categories: Miscellaneous Tags: ,

Sun Certified Enterprise Architect Assignment

November 25th, 2009 No comments

The  Sun Certified Enterprise Architect(SCEA) consists from Sun consists of 3 parts

a) Objective questions and answers

b) Assignment

c) Essay

The details can be found here Sun Certified Enterprise Architect . The assignment is one of the challenging parts. I had prepared for examination way back in 2004 and had prepared some notes. I am trying to dig up the notes from my old cd and today I found a document which helped me in clarifying my doubts on Part 2. I am not posting the solution but only some questions and answers which will help you understand the assignment better. Read more…

Relationships in UML explained

November 24th, 2009 No comments

The following table shows the kinds of UML relationships between classes, their notation, and what they mean

Association : When two classes are connected to each other in any way, an association relation is established. For example A “student studies in a college” association can be shown as:

association Relationhsip

association Relationhsip

Read more…

Categories: Programming / tutorials Tags: ,

Design Patterns in Dynamic Programming

November 8th, 2009 No comments

Peter Norvig has put in a presentation in which he re visits the GOF design patterns and explains how the implementation would change for dynamic languages.

To see the complete presentation visit Design Patterns in Dynamic Programming

It is a very old presentation but might hold true for some of the dynamic languages of today.

Categories: Programming / tutorials Tags: ,

GOF Design patterns quiz

September 30th, 2009 No comments

A new test on GOF Design patterns has been added on skill-guru. GOF(Gang of four) design patterns are generally considered the foundation for all other patterns. They are categorized in three groups: Creational, Structural, and Behavioral.

This GOF Patterns test covers the important patterns.

This is also helpful for Sun Certified Enterprise Architect Preparation.

Difference between Factory and Abstract Factory

September 14th, 2009 No comments

Abstract Factory: This is a Creational pattern.
It provides an interface for creating families of related or dependent objects (products) without specifying their concrete classes.
J2EE technology uses this pattern for the EJB Home interface, which creates new EJB objects.
It isolates concrete classes.
It makes exchanging product families easy.
It promotes consistency among products.
Supporting new kinds of products is difficult

Factory Method : This pattern defines an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.
J2EE technology uses this pattern for the EJB Home interface, which creates new EJB objects.
Eliminates the need to bind application-specific classes into your code.
Gives subclasses a hook for providing an extended version of an object being constructed.

Difference between Factory and Abstract Factory
The Factory Method pattern is for creating a single object type. It provides a generic interface for client objects, and defers instantiation to subclasses that implement the generic interface.

The Abstract Factory pattern is for creating multiple, related objects, and defers instantiation to subclasses that implement the generic interface of the factory object

Categories: Programming / tutorials Tags: ,

Difference between Aggregation and Composition

August 26th, 2009 11 comments

When studying UML , one of the most important questions which comes to mid of a programmer is , What is the difference between Aggregation and Composition ?

Composition and Aggregation are types of associations. They are very closely related and in terms of programming there does not appear much difference.  I will try to explain the difference between these two by java code examples

Aggregation: the object exists outside the other, is created outside, so it is passed as an argument (for example) to the construtor. Ex: People – car. The car is create in a different context and than becomes a person property.

Composition: the object only exists, or only makes sense inside the other, as a part of the other. Ex: People – heart. You don’t create a heart and than passes it to a person.

Code example for aggregation:

// WebServer is aggregated of a HttpListener and a RequestProcessor

public class WebServer {
private HttpListener listener;
private RequestProcessor processor;
public WebServer(HttpListener listener, RequestProcessor processor) {
this.listener = listener;
this.processor = processor;
}
}

Code example for composition

// WebServer is an composition of HttpListener and RequestProcessor and controls their lifecycle

public class WebServer {
private HttpListener listener;
private RequestProcessor processor;
public WebServer() {
this.listener = new HttpListener(80);
this.processor = new RequestProcessor('/www/root');
}
}

In composition, whole has responsibility of preventing garbage collection of part.

Categories: Programming / tutorials Tags: , , ,