In
knowledge representation
Knowledge representation and reasoning (KRR, KR&R, KR²) is the field of artificial intelligence (AI) dedicated to representing information about the world in a form that a computer system can use to solve complex tasks such as diagnosing a medic ...
,
object-oriented programming
Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of pr ...
and
design
A design is a plan or specification for the construction of an object or system or for the implementation of an activity or process or the result of that plan or specification in the form of a prototype, product, or process. The verb ''to design'' ...
(see
object-oriented
Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of pro ...
program architecture), is-a (is_a or is a) is a
subsumption
Subsumption may refer to:
* A minor premise in symbolic logic (see syllogism)
* The Liskov substitution principle in object-oriented programming
* Subtyping in programming language theory
* Subsumption architecture in robotics
* A subsumption ...
relationship between
abstractions
Abstraction in its main sense is a conceptual process wherein general rules and concepts are derived from the usage and classification of specific examples, literal ("real" or "concrete") signifiers, first principles, or other methods.
"An abstr ...
(e.g.
types
Type may refer to:
Science and technology Computing
* Typing, producing text via a keyboard, typewriter, etc.
* Data type, collection of values used for computations.
* File type
* TYPE (DOS command), a command to display contents of a file.
* Typ ...
,
classes), wherein one
class
Class or The Class may refer to:
Common uses not otherwise categorized
* Class (biology), a taxonomic rank
* Class (knowledge representation), a collection of individuals or objects
* Class (philosophy), an analytical concept used differentl ...
''A'' is a
subclass of another class ''B'' (and so ''B'' is a
superclass of ''A'').
In other words, type A is a subtype of type B when A's
specification
A specification often refers to a set of documented requirements to be satisfied by a material, design, product, or service. A specification is often a type of technical standard.
There are different types of technical or engineering specificati ...
implies B's specification. That is, any object (or class) that satisfies A's specification also satisfies B's specification, because B's specification is weaker.
The ''is-a'' relationship is to be contrasted with the ''
has-a
In database design, object-oriented programming and design (see object oriented program architecture), has-a (has_a or has a) is a composition relationship where one object (often called the constituted object, or part/constituent/member object) ...
'' (''has_a'' or ''has a'') relationship between types (classes); confusing the relations ''has-a'' and ''is-a'' is a common error when designing a model (e.g., a
computer program
A computer program is a sequence or set of instructions in a programming language for a computer to execute. Computer programs are one component of software, which also includes documentation and other intangible components.
A computer program ...
) of the real-world relationship between an object and its subordinate. The ''is-a'' relationship may also be contrasted with the ''
instance-of'' relationship between objects (instances) and types (classes): see
Type–token distinction
The type–token distinction is the difference between naming a ''class'' (type) of objects and naming the individual ''instances'' (tokens) of that class. Since each type may be exemplified by multiple tokens, there are generally more tokens than ...
.
To summarize the relations, there are:
*
hyperonym
In linguistics, semantics, general semantics, and ontologies, hyponymy () is a semantic relation between a hyponym denoting a subtype and a hypernym or hyperonym (sometimes called umbrella term or blanket term) denoting a supertype. In other wor ...
–
hyponym
In linguistics, semantics, general semantics, and ontologies, hyponymy () is a semantic relation between a hyponym denoting a subtype and a hypernym or hyperonym (sometimes called umbrella term or blanket term) denoting a supertype. In other wor ...
(supertype/superclass–subtype/subclass) relations between types (classes) defining a taxonomic hierarchy, where
** for a
subsumption
Subsumption may refer to:
* A minor premise in symbolic logic (see syllogism)
* The Liskov substitution principle in object-oriented programming
* Subtyping in programming language theory
* Subsumption architecture in robotics
* A subsumption ...
relation: a hyponym (subtype, subclass) has a ''type-of'' (''is-a'') relationship with its hyperonym (supertype, superclass);
*
holonym
In linguistics, meronymy () is a semantic relation between a meronym denoting a part and a holonym denoting a whole. In simpler terms, a meronym is in a ''part-of'' relationship with its holonym. For example, ''finger'' is a meronym of ''hand'' ...
–
meronym
In linguistics, meronymy () is a semantic relation between a meronym denoting a part and a holonym denoting a whole. In simpler terms, a meronym is in a ''part-of'' relationship with its holonym. For example, ''finger'' is a meronym of ''hand'' ...
(whole/entity/container–part/constituent/member) relations between types (classes) defining a possessive hierarchy, where
** for an
aggregation (i.e. without ownership) relation:
*** a holonym (whole) has a ''has-a'' relationship with its meronym (part),
** for a
composition
Composition or Compositions may refer to:
Arts and literature
*Composition (dance), practice and teaching of choreography
*Composition (language), in literature and rhetoric, producing a work in spoken tradition and written discourse, to include v ...
(i.e. with ownership) relation:
*** a meronym (constituent) has a ''
part-of
In linguistics, meronymy () is a semantic relation between a meronym denoting a part and a holonym denoting a whole. In simpler terms, a meronym is in a ''part-of'' relationship with its holonym. For example, ''finger'' is a meronym of ''hand'' ...
'' relationship with its holonym (entity),
** for a
containment
Containment was a geopolitical strategic foreign policy pursued by the United States during the Cold War to prevent the spread of communism after the end of World War II. The name was loosely related to the term ''cordon sanitaire'', which was ...
relation:
*** a meronym (member) has a ''member-of'' relationship with its holonym (
container
A container is any receptacle or enclosure for holding a product used in storage, packaging, and transportation, including shipping.
Things kept inside of a container are protected on several sides by being inside of its structure. The term ...
);
* concept–object (type–token) relations between types (classes) and objects (instances), where
** a token (object) has an ''
instance-of'' relationship with its type (class).
Examples of subtyping
Subtyping
In programming language theory, subtyping (also subtype polymorphism or inclusion polymorphism) is a form of type polymorphism in which a subtype is a datatype that is related to another datatype (the supertype) by some notion of substitutabilit ...
enables a given type to be substituted for another type or abstraction. Subtyping is said to establish an is-a relationship between the subtype and some existing abstraction, either implicitly or explicitly, depending on language support. The relationship can be expressed explicitly via inheritance in languages that support inheritance as a subtyping mechanism.
C++
The following C++ code establishes an explicit inheritance relationship between classes B and A, where B is both a subclass and a subtype of A, and can be used as an A wherever a B is specified (via a reference, a pointer or the object itself).
class A
;
class B : public A
;
void UseAnA(A const& some_A)
void SomeFunc()
[
]
Python
The following python code establishes an explicit inheritance relationship between classes and , where is both a subclass and a subtype of , and can be used as an wherever a is required.
class A:
def do_something_a_like(self):
pass
class B(A):
def do_something_b_like(self):
pass
def use_an_a(some_a):
some_a.do_something_a_like()
def some_func():
b = B()
use_an_a(b) # b can be substituted for an A.
The following example, is a "regular" type, and is a metatype. While as distributed all types have the same metatype (, which is also its own metatype), this is not a requirement. The type of classic classes, known as , can also be considered a distinct metatype.
>>> a = 0
>>> type(a)
>>> type(type(a))
>>> type(type(type(a)))
>>> type(type(type(type(a))))
Java
In Java, is-a relation between the type parameters of one class or interface and the type parameters of another are determined by the extends and
implements clauses.
Using the classes, implements , and extends . So is a subtype of , which is a subtype of . The subtyping relationship is preserved between the types automatically. When defining an interface, , that associates an optional value of
generic type
Generic programming is a style of computer programming in which algorithms are written in terms of types ''to-be-specified-later'' that are then ''instantiated'' when needed for specific types provided as parameters. This approach, pioneered by ...
P with each element, its declaration might look like:
interface PayloadList extends List
The following parameterizations of PayloadList are subtypes of :
PayloadList
PayloadList
PayloadList
Liskov substitution principle
Liskov substitution principle explains a property, ''"If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2 then S is a subtype of T,"''. Following example shows a violation of LSP.
void DrawShape(const Shape& s)
Obviously, the DrawShape function is badly formatted. It has to know about every derivative classes of Shape class. Also, it should be changed whenever new subclass of Shape are created. In
object-oriented design
Object-oriented design (OOD) is the process of planning a system of interacting objects for the purpose of solving a software problem. It is one approach to software design.
Overview
An object contains encapsulated data and procedures grouped t ...
, many view the structure of this as anathema.
Here is a more subtle example of violation of LSP:
class Rectangle
;
This works well but when it comes to Square class, which inherits Rectangle class, it violates LSP even though the is-a relationship holds between Rectangle and Square. Because square is rectangular. The following example overrides two functions, Setwidth and SetHeight, to fix the problem. But fixing the code implies that the design is faulty.
public class Square : Rectangle
;
void Square::SetWidth(double w)
void Square::SetHeight(double h)
The following example, function g just works for Rectangle class but not for Square, and so the open-closed principle has been violated.
void g(Rectangle& r)
See also
*
Inheritance (object-oriented programming)
In object-oriented programming, inheritance is the mechanism of basing an object or class upon another object ( prototype-based inheritance) or class ( class-based inheritance), retaining similar implementation. Also defined as deriving new classe ...
*
Liskov substitution principle
The Liskov substitution principle (LSP) is a particular definition of a subtyping relation, called strong behavioral subtyping, that was initially introduced by Barbara Liskov in a 1988 conference keynote address titled ''Data abstraction and h ...
(in
object-oriented programming
Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of pr ...
)
*
Subsumption
Subsumption may refer to:
* A minor premise in symbolic logic (see syllogism)
* The Liskov substitution principle in object-oriented programming
* Subtyping in programming language theory
* Subsumption architecture in robotics
* A subsumption ...
* Is-a
**
Hypernymy
In linguistics, semantics, general semantics, and ontologies, hyponymy () is a semantic relation between a hyponym denoting a subtype and a hypernym or hyperonym (sometimes called umbrella term or blanket term) denoting a supertype. In other wor ...
(and
supertype
In programming language theory, subtyping (also subtype polymorphism or inclusion polymorphism) is a form of type polymorphism in which a subtype is a datatype that is related to another datatype (the supertype) by some notion of substitutability, ...
)
**
Hyponymy
In linguistics, semantics, general semantics, and ontologies, hyponymy () is a semantic relation between a hyponym denoting a subtype and a hypernym or hyperonym (sometimes called umbrella term or blanket term) denoting a supertype. In other wor ...
(and
subtype
Subtype may refer to:
* Viral subtypes, such as Subtypes of HIV
* Subtyping
In programming language theory, subtyping (also subtype polymorphism or inclusion polymorphism) is a form of type polymorphism in which a subtype is a datatype that is ...
)
*
Has-a
In database design, object-oriented programming and design (see object oriented program architecture), has-a (has_a or has a) is a composition relationship where one object (often called the constituted object, or part/constituent/member object) ...
**
Holonymy
In linguistics, meronymy () is a semantic relation between a meronym denoting a part and a holonym denoting a whole. In simpler terms, a meronym is in a ''part-of'' relationship with its holonym. For example, ''finger'' is a meronym of ''hand'' ...
**
Meronymy
In linguistics, meronymy () is a semantic relation between a meronym denoting a part and a holonym denoting a whole. In simpler terms, a meronym is in a ''part-of'' relationship with its holonym. For example, ''finger'' is a meronym of ''hand'' ...
Notes
{{reflist, 30em
References
*
Ronald J. Brachman
Ronald Jay "Ron" Brachman (born 1949) is the director of the Jacobs Technion-Cornell Institute at Cornell Tech. Previously, he was the Chief Scientist of Yahoo! and head of Yahoo! Labs. Prior to that, he was the Associate Head of Yahoo! Labs and H ...
What IS-A is and isn't. An Analysis of Taxonomic Links in Semantic Networks IEEE Computer, 16 (10); October 1983
* Jean-Luc Hainaut, Jean-Marc Hick, Vincent Englebert, Jean Henrard, Didier Roland
ER 1996: 42-57
Object-oriented programming
Knowledge representation
Abstraction
Articles with example Java code