IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
Coder
Search Coder Group:

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

Prestwood eMagazine

October 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 16 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 = P1116A1
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
21665
Since 4/2/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]