Is-a
   HOME

TheInfoList



OR:

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 ...
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 ...
program architecture Software architecture is the fundamental structure of a software system and the discipline of creating such structures and systems. Each structure comprises software elements, relations among them, and properties of both elements and relations. ...
), is-a (is_a or is a) is a subsumption relationship between abstractions (e.g. types, 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 differently ...
''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 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'' (''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 Execution (computing), execute. Computer programs are one component of software, which also includes software documentation, documentation and oth ...
) 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. To summarize the relations, there are: * hyperonymhyponym (supertype/superclass–subtype/subclass) relations between types (classes) defining a taxonomic hierarchy, where ** for a subsumption relation: a hyponym (subtype, subclass) has a ''type-of'' (''is-a'') relationship with its hyperonym (supertype, superclass); * holonymmeronym (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 (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 ...
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 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 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, 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 clas ...
*
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 ...
(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 ...
) * 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 wo ...
(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 ...
(and subtype) * Has-a ** Holonymy ** Meronymy


Notes

{{reflist, 30em


References

* Ronald J. Brachman
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