Skip to main content

Design Patterns

A note on Design patterns

Many times we can see ourselves looking for design patterns to fit the design of a requirement.
Of course if the requirement is simple enough to apply any existing design pattern we should do so. This will save us valuable time.

In my opinion it is better not to worry about which pattern to apply.But concentrate on the
three basic Object oriented principles.

1) Encapsulate what varies
2) Prefer composition over inheritance
3) Program to an interface not to an implementation.

If we approach the design with these principles in mind , we don't have to search for patterns. Pattern will emerge itself. Once we apply these principles, we can definitely look whether any of the existing patterns can solve the issue better than the way we thought of. This way our thinking process will improve tremendously and at times we may end up creating a solution which may be better than any available design patterns.

Comments

The points you mentioned are important aspect, however these are not the only design aspects, eg: layering, Modularity etc. In my opinion, for most of the enterprise applications, most critical issue is deciding the functional modules and relationship between them.

Popular posts from this blog

Using Database login Module in JBoss

This post is a detailed description on how to use the database login module in JBoss with a J2EE Application. Scenario There is a EJB and we want to restrict the access to this ejb's method to an authenticated user having a particular role. The EJB is accessed from a standalone Java Client using Remote Lookup. Implementation The EJB is HelloSSB and the roles allowed are admin and user. First step is to write the EJB The source code is given below. This is a stateless session bean. package com.prem.ejb; import javax.annotation.PreDestroy; import javax.annotation.Resource; import javax.annotation.security.RolesAllowed; import javax.ejb.SessionContext; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.jboss.annotation.security.SecurityDomain; @Stateless @SecurityDomain ("helloworld") public class HelloSSB implements HellioIntf{ @PersistenceContext(unitName = "EntApp") EntityManager em; @Reso...

Java - Too Many web frameworks

Hmm......... Java Web technology is exploding with many web frameworks promoted by the industry and many by opensource. Too many frameworks to choose from is a bad thing or good thing ?. Read on and judge yourselves. May be too much of anything is bad. Just look at the list below. JSF Spring MVC Tapestry Struts 2 ADF from Oracle Cocoon Maverick JBoss seam This is a never ending list. There are many more. Ofcourse not all are mainstream nowadays. Look at Microsoft stack , you mainly have ASP .NET and that's it. It has grown well.You need to learn only that and you focus all your skills in that web framework.It has accumulated many components and matured into a very robust RAD web application framework. The problem with the Java stream is you work on a particular web framework for sometime and all of a sudden you have to work in another web framework for another project.Hence the experiance one gains by working in a particular framework for long time, gets lost. This definitly lowers...