Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HAS-A, IS-A terminology in object oriented language

Tags:

oop

I was just reading through the book and it had the terms, "HAS-A" and "IS-A" in it. Anyone know what they mean specifically? Tried searching in the book, but the book is 600 pages long.

like image 303
Jeremy Avatar asked Feb 08 '10 00:02

Jeremy


People also ask

What are the object-oriented terminologies?

Object-oriented methodology is a way of viewing software components and their relationships. Object-oriented methodology relies on three characteristics that define object-oriented languages: encapsulation, polymorphism, and inheritance. These three terms are elaborated below.

Is a and has a in OOP?

OOP (Object Oriented Programming) has two common relationship of objects. It's call “Is-A” and “Has-A” relationship. To avoid long description that make you confused, I have a very short description that make you get concept in a minute.

Is a VS has a VS uses a?

as cletus points out, is-a is different. but be careful with has-a. this can mean composition (lifetime responsbility), aggregation (part-of something), or simply uses-a (has a reference to, knows how to build one or find one). the latter is just an association.

What is has a relationship in oops?

An IS-A relationship is inheritance. The classes which inherit are known as sub classes or child classes. On the other hand, HAS-A relationship is composition. In OOP, IS-A relationship is completely inheritance.


2 Answers

This is object-oriented programming and UML terminology, not Java-specific. There are actually three cases you should be aware of:

  1. A House is a Building (inheritance);
  2. A House has a Room (composition);
  3. A House has an occupant (aggregation).

The difference between (2) and (3) is subtle yet important to differentiate. Together they are forms of association. What's the difference? Composition implies the child object cannot live out of the context of the parent (destroy the house and rooms disappear) whereas aggregation implies the child can exist on its own (destroy the house and the occupant goes elsewhere).

like image 125
cletus Avatar answered Sep 20 '22 21:09

cletus


A Car has-a Wheel.

A Sparrow is-a Bird.

Academically, the terms are used to decide between composition and inheritance.

like image 26
Anon. Avatar answered Sep 16 '22 21:09

Anon.