Subclass and subtype.

This is a discussion on Subclass and subtype. within the C++ Programming forums, part of the General Programming Boards category; In oop what is the difference between a subclass and a subtype?...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    37

    Subclass and subtype.

    In oop what is the difference between a subclass and a subtype?

  2. #2
    Registered User
    Join Date
    Jul 2003
    Posts
    450
    I haven't really heard the word subtype used too much but I don't think there is a difference.

  3. #3
    C Programmer Stack Overflow's Avatar
    Join Date
    Apr 2004
    Posts
    477
    Hello,

    A subtype is a specialized version of a type. In C++ a derived class is a subtype (subclass) of a base class type. A variable of the derived type could appear anywhere that a variable of the parent type is requested.

    Characteristics of a subclass that guarantees it is a subtype:
    Can only add variables and methods or redefine existing methods in a compatible way.

    If the subclass hides some of the parents variables and functions or modifies them in an incompatible way, then it does not create a subtype.

    What is a compatible way?
    By imposing some restrictions on the use of inheritance, the language can ensure substitutability.

    If you would like more information, check out the following link: Subtyping vs. Subclassing


    - Stack Overflow
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    When you use "subclass" do you mean the MFC and winapi method of subclassing a control? A subtype of another type means you can use the subtype in all situations where the parent type could be used. With C+, you not only have the subtype relation between two class(which should occur with proper inheritance trees), but also have protected and private inheritance.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21