some help please


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: some help please

  1. #1
    Join Date
    Nov 2007
    Posts
    4

    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
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Have a look at this. Does this clear anything up for you?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

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