View RSS Feed

Java Object

Object-oriented programming in Java.

  1. Choosing composition vs. inheritance

    by , 04-26-2012 at 06:14 PM
    Both inheritance and composition permits you to put the sub-objects in new class. One may be amazed regarding the difference present b/w two and when one could be chooses over the other.

    Generally, composition is used if an existing class features are required in your new class but not the interface. This means that an object is embedded to use it for implementation of functionality of your new class. However, your new class user may see the interface that has been defined instead ...
    Categories
    Composition
  2. Using Inheritance - Substitution vs. Extension

    by , 11-30-2011 at 02:51 AM
    We are going to look at inheritance hierarchy. If we take a classic approach, as shown below we would see the methods that have been defined in the base class overridden in the derived classes. Inheritance guarantees that any derived class will have the interface of the base class. If you follow this diagram below, derived classes will also have no more than the base-class interface.

    Name:  Inheritance-Example.jpg
Views: 806
Size:  16.7 KB

    This can be thought of as pure substitution, because ...
  3. Design Principle: Choose Composition vs. Inheritance

    by , 11-30-2011 at 02:48 AM
    With composition or inheritance you can place sub-objects inside your new class. If you do this explicitly than you are using composition otherwise if you do this implicitly, you are using inheritance. I will outline the difference between the two below as well as point out one of the key design patterns to use in your development. Prefer composition vs inheritance.

    Composition is used when you want the features of an existing class to be included inside your new class, but not be ...
  4. Composition Syntax for Reuse

    by , 11-29-2011 at 05:21 PM
    One of the best features of Java is code reuse. But like any tool, it needs to be used effectively. Most programmers might be lead to think that when I talk of reuse only relates to extending a class. Now there is nothing wrong with reusing a class by extending it or using it directly. This type of reuse is using the class without the risk changing the existing code. First we can create objects of the existing class inside the new class. We call this composition. It is a new class composed of objects ...
  5. Composition Rather than Inheritance

    by , 11-29-2011 at 01:27 AM
    One of the more abused features of object oriented languages is inheritance. Second on the list of abused features of Java as an outgrowth of inheritance is the use of polymorphism. Developers seem to believe that everything should be inherited, and that classes should use polymorphism for every object irrespective of whether the arguments will be provided from external sources. Doing these sorts of things will make your designs more difficult to understand and lead to complications later when ...