Thread: Subclass and subtype.

  1. #1
    Registered User
    Join Date
    Feb 2002

    Subclass and subtype.

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

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

  3. #3

    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 parent’s 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
    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