DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Understanding

  1. #1
    Ali Imran Guest

    Understanding


    Friends,

    We usally, use Abstract class to make some common code, so later we can update
    or modify or code in a single place rather then modifying it other places...
    Can anbody give me some practical example of why we use Interfaces? and why
    they are called a method to provide multiple inheritence?

    Please help..

    Thanks.
    Ali Imran.




  2. #2
    Arthur Wood Guest

    Re: Understanding


    Ali,
    I built an application several years ago to manage the member slist of
    a small church. Some of the Members were Children and some were Adults.
    All of the members had a Name (First and Last), a Birthdate. Children also
    had properties for the Grade in school. the name of the school they attended,
    and whether they has attended Vacation Bble School, while Adults had propeties
    from their job-title, their place of employment, their e-mail address, and
    whther or not they had served as an Elder in the church.

    I created a "base Class" CPerson which exposed the Interface which was common
    to both Children and Adults (after all Children AND Adults are Persons)-
    FirstName as String, LastName as String, BirthDate as Date, PersonType as
    Integer (1=> Adult, 2=> Child).

    Then in the cChild Class, I Implemented the cPerson Class, and extended the
    cChild class with the additional properties that were needed for a Child
    (Grade as Integer, School as String), setting PersonType = 2.

    In the cAdult Class I again Impleneted the cperson class, and extended with
    the properties necessary for an Adult (JobTitle as String, Employer as String,
    Elder as Boolean), setting PersonType = 1.

    I could then create a cFamily class which held a collection of cPerson objects
    (including there BOTH Adult and Children objects, since they both exposed
    the Person Interface, and so in that sense were of the same type, and could
    be distinguished by the PersonType of the member object in the collection).

    Worked like a charm.

    Arthur Wood


    "Ali Imran" <aimran@saudionline.com.sa> wrote:
    >
    >Friends,
    >
    >We usally, use Abstract class to make some common code, so later we can

    update
    >or modify or code in a single place rather then modifying it other places...
    >Can anbody give me some practical example of why we use Interfaces? and

    why
    >they are called a method to provide multiple inheritence?
    >
    >Please help..
    >
    >Thanks.
    >Ali Imran.
    >
    >
    >



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