DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2007

    Question some help please

    A subclass can inherit "interface" or "implementation" from a superclass. How do inheritance hierarchies designed for inheriting interface, differ from those designed for inheriting implementation (behavioral characteristics of a class)?

  2. #2
    Join Date
    Apr 2007
    Sterling Heights, Michigan
    Have a look at this. Does this clear anything up for you?

  3. #3
    Join Date
    Dec 2004
    San Bernardino County, California
    Your decision in this matter is based upon your implementation of Object Oriented Programming.

    In my implementation, the more that a child class "is a" type of the parent, the more I want to use inheritance. I want the child to have many of the fields and methods of the parent (not implementing its own versions) except for those special fields or methods which differentiate the child from the parent. Think of Bird parent and its child classes, or Shape and all of the shape children, or Person and all the types of persons which your program might interact with.

    When I use one or more interfaces in my code, it is because I want a user of the class to know that my class is capable of performing a certain task or set of tasks for the calling class. This kind of "performs a" relationship is the separation of concerns part of OOP. I don't have to have all of my classes performing all operations. I can design specialists to perform a task which many classes will need to perform. The many classes can send a message to the class which will perform the task for them, and that class will return the answer or move the system to the next state for them. The calling class does not need to know how the called class does its job, just needs to know how to format the call to the method it wants to implement. On the flip side, I may not want the calling classes to know how I implement the algorithm or method that the called class is executing (trade secret) and I want the flexibility to modify my implementation but I don't want to force the re-write the code of all of the other classes which might call this class. Therefore, I write the interface - which sets out the method calls which the special purpose class will implement - which remains the same, known to all of the potential calling classes, then I implement that interface in one or more called classes. I can "cast" the interface to the implementing class.

    Inheritance from a parent = "is a" relationship
    Implementing an interface = "performs a" relationship

    In Java - single inheritance, multiple implementation

    Yes, you can write "is a" type relationships into an implementation of an interface, and child classes perform the same functions as a parent (perhaps in their own way), but it is all a matter of your design choices in your implementation.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.