Solved

I am trying to explain Extend & Interface through anological way . Does these sound Correct !

Posted on 2004-09-05
2
171 Views
Last Modified: 2010-03-31
I am trying to define the Extending and Interface definitions in an analogical way . Let me know if this will be OK ?


Extending Analogical Example

Parental Property Inheritance                  |      The concepts of Object Oriented
                                                         |      Inheritance  is also the same .
                                                         |
                                                         |
Inherited Parental Property  means you |      It  means that  you  have  all  the data variables and
had inherited every thing what your      |      Methods of the parent class. This enables you have
parents had without much hard work!   |      More  lines  of code with the required logic  without
                                                         |     much hard work.


If you are renovating your parents property        |  class MyPropertyClass extends ParentPropertyClass
by adding a  swimming pool  and car park    |  {
besides that  house  all you do is spend        |//You write  the body of swimming Pool;
money  to build only  for  these two  things,  |   //You write the body  of Car Park;
so you  save  money by not building a house.|  // You need not write about the house as you are
So  if you come from aKings family you              |  //extending your  parents house;
could inherit all your  Parents,Grand Parents |   }
Etc. If you  destroy the property you   have   |
nothing   and  in  in   JAVA it is called           |
Method Over-ridding.                                  |
                                     
      
                                                
                                                                Even JAVA there is no limit in the number  of
                                                                extensions  but  remember each class can extend
                                                               only one  super class  at  a time as JAVA does not
                                                                support Multiple inheritance



INTERFACE EXAMPLE
 
            AIRPORT CHECK-IN                                |      CLIENT CHECK-IN.
                                                                        |
When  you  want to  Fly out to another               |   Even  in  OO  Technique  the Bean  
country you  can   board  the  Aircraft                    |  Classes are not directly Exhibited to the
only  when you show  your passports which          |  Clients but uses an Interface  
has your Signature, Expiry Date    etc.                    | which has the method structure  
This means  that the CLERK identifies you                | i.e  method signatures  of the Class  
through the Passport as she sees Your                 | with no  logic   or  you  can say            
 image and Signature .                                       |  Interface has the skeleton of the Class.
                                                                        |  The Clients talk to the bean Class
                                                                        | through  the interface.
                  


                                                                        | So analogically  if you want to compare  
                                                                        |  with the Airport Check-in     example   the
CLERK LOOKS INTO PASSPORTs TO KNOW           | Clerk will be your client ,The passport  which
                                           THE PASSENGER     |  identifies you will be  the interface as it has
                                                                        |  your structure i.e  your PHOTO  and
                                                                        | Signature and you  will  represent  
CLIENT LOOKS INTO  INTERFACE  TO KNOW              |  the  bean .So without
                                               BEAN CLASS       | Passport  you are  not  allowed  to  
                                                                        |  board  the   Aircraft  and   with   out
                                                                        |  INTERFACE the  BEAN will not do anything
                                                                        |  for you .
                              

                                                                         NOTE:
                                                                        There will no implementation in an  
                                                                        INTERFACE .So INTERFACE is like having the
                                                                        PHOTO of the Class.
      
0
Comment
Question by:Kanti
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 11985004
No I don't like this story. It's too synthetic and too long. Try this:

In a hospital: everybody in a long white coat and a stethoscope is taken for a doctor:  INTERFACE, the patients sight.
In fact it takes many years to study and to promote to be a surgeon: EXTEND, the administration's sight.

I am a hired programmer and sit beside the customers employees.
I'm an INTERFACE (to the team) they are only intereseted in my skill.
The person right to me is a CLASS: he/she is an employee and will be promoted on success (EXTENSION).

From sheer frustration, ;JOOP!

0
 
LVL 3

Accepted Solution

by:
sbockelman earned 125 total points
ID: 11986548
First get the definitions as far as Java is concerned correct, then...if you want to make up a story go ahead, but...

1.  "extends" *should* mean simply that object B "is an" object A, but with additional abilities (that is it can handle all message sent to object A, plus some).  In Java and many OO languages, it can also mean, that object B "is like an" object A (that is it responds to all the same messages and *maybe* some additional ones, but its behavior when responding may vary.)  This is not the purist intention of class-inheritance and should be frowned upon.  So...

extends should mean "does everything the base class does exactly the same way and also does a few new things"

2. an interface is simply a description of the kinds of messages an object that implements that interface will respond to, with no necessarily implied notion of how such an object will respond, though it is usually customary that each iomplementing class will appear to respond similarly.

So, an anology for extends is something like:

Employee extends Person

A person will respond to getName() with its name.
An employee will repsond to getName() with its name.
An employee can also respond to getSalary(), while a "mere" Person cannot.

Both such objects also apparently implement the "Named" interface, responding to getName().
You might have an example like this:

Bridge
City
Person
Employee
Disease

All of these classes could implement the "Named" interface, but certainly, I would be surprised if there was any class hierarchy in which all of these classes could reasonably reside as extensions of one another.

However, given a collection of such things, each item in the collection could be cast to Named and respond to a call to getName().

I hope this rambling helps you better explain the differences.

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Certificat to iSeries KeyStore 1 31
Java exception bubble up 2 26
How to convert from xls to xlsx using java 7 160
glassfish admin console 1 53
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question