Bridge Pattern and Marker Interface

Can any one explain,
      -->   the implementation of bridge-pattern,
     -->   Also about Marker Interface.

Bridge Pattern as the name suggests is used maily to decouple the interface and the class implementing the interface.
Another obvious advantage is the extensibility provided in terms of Future enhancements.
Also, hiding the actual implementation from the Client.

Marker Interfaces are interfaces in Java that have no behavior.   In other words, they are just empty interface definitions.
For example in the Java API java.io.Serializable, Cloneable etc.

Pallav

Then regarding marker interface,  I have some basic understanding.

All interfaces can act as marker interface but null interfaces are the most suited for it. also every interface has a boolean flag and that boolean flag goes for the entire generation of classes implenting that interface. I understand this boolean flag is the marker. What I want to know how this stuff is working in detail?

Bharath Chinnadurai

The following is for Marker Interface:

Marker Interface
One of the "clean" features of the Java programming language is that it mandates a separation between interfaces (pure behavior) and classes (state and behavior). Interfaces are used in Java to specify the behavior of derived classes.
Often you will come across interfaces in Java that have no behavior. In other words, they are just empty interface definitions. These are known as marker interfaces. Some examples of marker interfaces in the Java API include:

- java,lang.Cloneable
- java,io.Serializable
- java.util.EventListener

Marker interfaces are also called "tag" interfaces since they tag all the derived classes into a category based on their purpose. For example, all classes that implement the Cloneable interface can be cloned (i.e., the clone() method can be called on them). The Java compiler checks to make sure that if the clone() method is called on a class and the class implements the Cloneable interface. For example, consider the following call to the clone() method on an object o:

SomeObject o = new SomeObject();
SomeObject ref = (SomeObject)(o.clone());

If the class SomeObject does not implement the interface Cloneable (and Cloneable is not implemented by any of the superclasses that SomeObject inherits from), the compiler will mark this line as an error. This is because the clone() method may only be called by objects of type "Cloneable." Hence, even though Cloneable is an empty interface, it serves an important purpose.

Marker interfaces are simply interfaces which are blank i.e. without any methods, fields.
Mostly you will find the Marker Interfaces been defined in the JVM. So although Serializable is an interface without any methods you will find an implementation in JVM for the interface with readObject and writeObject methods. Again same goes for Cloneable interface there is a method clone which is implemented in JVM.

Also you can very well override these methods in your class and provide an implementation which is specific to your need.

Pallav

Related:

Java Books
Java Certification, Programming, JavaBean and Object Oriented Reference Books

Return to : Java Programming Hints and Tips

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.