I.T. Discussion Community!
-Collapse +Expand
Coder
Search Coder Group:

Advanced
-Collapse +Expand Coder Study Test
PRESTWOODCERTIFIED
-Collapse +Expand Coder Store
PRESTWOODSTORE

Prestwood eMagazine

February Edition
Subscribe now! It's Free!
Enter your email:

   ► KBRole-Based T...Coding & OOObject Orien...   Print This     
  From the October 2015 Issue of Prestwood eMag
 
Coder Object Orientation (OO):
Inheritance
 
Posted 11 years ago on 1/23/2008 and updated 1/5/2009
Take Away:

The concept of a class makes it possible to define subclasses that share some or all of the main class characteristics. This is called inheritance. Inheritance also allows you to reuse code more efficiently. In a class tree, inheritance is used to design classes vertically. (You can use Interfaces to design classes horizontally within a class tree.) With inheritance, you are defining an "is-a" relationship (i.e. a chow is-a dog). Analysts using UML call this generalization where you generalize specific classes into general parent classes.

Coder Definition Flashcard:
 A flashcard from our Coder Flashcards Library
 A definition from our Coder Definitions Page

KB100813



Inheritance -

The concept of a class makes it possible to define subclasses that share some or all of the main class characteristics. This is called inheritance. Inheritance also allows you to reuse code more efficiently. In a class tree, inheritance is used to design classes vertically. (You can use Interfaces to design classes horizontally within a class tree.) With inheritance, you are defining an "is-a" relationship (i.e. a chow is-a dog). Analysts using UML call this generalization where you generalize specific classes into general parent classes.


Inheritance is a type of class or object association. The concept of a class makes it possible to define subclasses that share some or all of the main class characteristics. This is called inheritance. Inheritance also allows you to reuse code more efficiently.

Designing with Inheritance

In a class tree, inheritance is used to design classes vertically. (You can use Interfaces to design classes horizontally within a class tree.) With inheritance, you are defining an "is-a" relationship (i.e. a chow is-a dog). Analysts using UML call this generalization where you generalize specific classes into general parent classes or take general parent classes and specialize them as needed in child classes.

Inheritance is Generalization

Inheritance is Generalization and the terms can almost be used synonymously. In general, I prefer to use the term generalization when talking to analysts trying to understand a problem domain and inheritance when talking to programmers who need to implement an OOP solution.

UML Symbol

UML Generalization Arrow

 

Inheritance-Based Polymorphism

A.k.a. Overriding, Inclusion Polymorphism, Runtime Polymorphism, Dynamic Binding, or Late Binding

A coding element which involves defining methods in a parent class and overriding them with new implementations in child classes. For example, you could define a method in a parent class and override it in descendant classes as needed. When using an object instantiated from one of these classes, you don't actually need to know which method implimentation is used, you just need to know the name of the method or property to use.

Polymorphism allows the software architect to design a dog.run and a cat.run method and then the programmer can decide at development time whether to instantiate a dog or cat object and either way he knows to call the run method to make the object run. If the designer created a MakeDogRun and a MakeCatRun methods, then the programmer would have a hard time remembering different commands and could not easily substitute one for the other.

Code Examples

Refer to the links below for code examples in various languages.

More Info

Code:  ASP Classic Inheritance (Not Supported)
Code:  C# Inheritance (: ParentClass)
Code:  C++ Inheritance (: public ParentClass)
Code:  Delphi Inheritance (=class(ParentClass))
Code:  Delphi Prism Inheritance (=class(ParentClass))
Definition:  Generalization
Code:  Java Inheritance (extends ParentClass)
Code:  JavaScript Inheritance (No, but sort of.)
Code:  ObjectPAL Inheritance (Not Supported)
Code:  VB Classic Inheritance (No, but see Implements.)
Code:  VB.Net Inheritance (Inherits ParentClass)

Comments

0 Comments.
Share a thought or comment...
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1182A1
Enter key:
Definition Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #100813 Counter
17247
Since 4/2/2008
-
   Contact Us!
 
PrestwoodBoards.com was developed and is maintainted by me. Do you have a question or suggestion? Do you see a problem? Contact me now. My goal is to build an ad-free and spam-free source of I.T. information with many contributers (ok to promote your website/company in your bio). Yes, my company Prestwood IT Solutions is mentioned in my bio which shows with every post, but you can contribute and promote your pet project too!

2,712 People Online Now!!  
Sign In to see who's online now!  Not a member? Join now. It's free!
Show more stats...


©1995-2019 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech