1.Use interfaces when I see that something in my design will change frequently. You should generally favor interfaces over inheritance when you want an object to have a certain type;
For example, the Strategy pattern lets you swap new algorithms and processes into your program without altering the objects that use them. A media player might know how to play CDs, MP3s, and wav files. Of course, you don't want to hardcode those playback algorithms into the player; that will make it difficult to add a new format like AVI. Furthermore, your code will be littered with useless case statements. And to add insult to injury, you will need to update those case statements each time you add a new algorithm. All in all, this is not a very object-oriented way to program.

2.What is an Abstract Class?
Java provides you with a special type of class, called an abstract class, which can help you, organize your classes based on common methods. An abstract class lets you put the common method names in one abstract class without having to write the actual implementation code. Following are the key points of abstract class –
Classes, which contain abstract methods, are called abstract classes.
A program cannot instantiated an abstract class as an object.
Abstract classes may contain a mixture of non-abstract and abstract methods. Non-abstract methods implement the method statements.
Any subclass, which extends the class containing abstract methods, must provide the implementation for all the abstract methods; otherwise the subclass itself becomes an abstract class.
Example: public abstract Class Book{
public abstract String readBook();
public abstract void writeBook(String text);

}
Many developers forget that a class that defines an abstract method can call that method as well. Abstract classes are an excellent way to create planned inheritance hierarchies. They're also a good choice for nonleaf classes in class hierarchies.

3.Difference between VO (Value Object) and DTO (Data Transfer Object)

- The motivation behind a VO is to wrap a single discrete value that can be tested for equivalence with another VO of that type
- The motivation behind a DTO is to wrap multiple discrete values so that they can be treated as a single, discrete, first-class object.

A DTO is basically a plain Java Bean class that contains the data that flows between different layers in the application.

The DTO, Transfer Object and Value Object are all similar, and have been used extensively by the J2EE community. A Value Object usually represents an immutable Java Bean object (get methods only) extracted from an Entity Bean through a getValueObject() method call, while the DTO is more generically used to refer to a Java Bean object holding data transferred through remote calls. The Transfer Object is used to describe the DTO used by business components that are either a Session Bean, an Entity Bean or a DAO (Data Access Object).

4. The Gang of Four Design Patterns book [2] describes the Facade pattern as "a unified interface to a set of interfaces in a subsystem. It defines a higher-level interface that makes the subsystem easier to use."; use a session bean as a facade to encapsulate the complexity of interactions between the business objects participating in a workflow. The Session Facade manages the business objects, and provides a uniform coarse-grained service access layer to clients.By employing the SessionFacade, the client is provided with a coarse-grained way to access the EJB Layer.

5. Use a Business Delegate to reduce coupling between presentation-tier clients and business services. The Business Delegate hides the underlying implementation details of the business service, such as lookup and access details of the EJB architecture

0 comments: