Subscribe to Java/SCJP        RSS Feed
- - - - -

Marker Interfaces

Icon Leave Comment
Marker interfaces don't declare any methods. They are provided so that a utility class can check if the object has opted to implement a particular functionality.
A simple example is the Serializable interface in java API.
- - - - -

Immutable classes

Icon Leave Comment
The objects which will not be changed too frequently then simply accessed should be made immutable. Though some utility functions can be provided to make changes. But the attributes should not be changed by the programmer once it has been set by the constructor.
To make a class' objects immutable, don't provide any setter methods.
A simple...
- - - - -

Interfaces

Icon Leave Comment
A number of classes providing the same functionality in different contexts can implement same interface and a class will compose a reference of interface and hence makes changes in any of the classes. This provides single accessor for classes providing same functionality in different context.

e.g.
...
- - - - -

When not to use inheritance

Icon Leave Comment
If the behaviour of a class changes with time, then that behaviour should not be implemented as inheritance because inheritance imposes static behaviour. Delegation/Composition should be used in such a case.

Page 1 of 1

January 2022

S M T W T F S
      1
2345678
9101112131415
161718192021 22
23242526272829
3031     

Recent Entries

Recent Comments

Search My Blog

10 user(s) viewing

10 Guests
0 member(s)
0 anonymous member(s)