`
oywl2008
  • 浏览: 1053376 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

IS-A Relationship And HAS-A Relationship

 
阅读更多


One of the advantages of an Object-Oriented programming language is code reuse. There are two ways we can do code reuse either by the vimplementation of inheritance (IS-A relationship), or object composition (HAS-A relationship). Although the compiler and Java virtual machine (JVM) will do a lot of work for you when you use inheritance, you can also get at the functionality of inheritance when you use composition.

IS-A Relationship:

In object-oriented programming, the concept of IS-A is a totally based on Inheritance, which can be of two types Class Inheritance or Interface Inheritance. It is just like saying "A is a B type of thing". For example, Apple is a Fruit, Car is a Vehicle etc. Inheritance is uni-directional. For example, House is a Building. But Building is not a House.

It is a key point to note that you can easily identify the IS-A relationship. Wherever you see an extends keyword or implements keyword in a class declaration, then this class is said to have IS-A relationship.

HAS-A Relationship: 

Composition(HAS-A) simply mean the use of instance variables that are references to other objects. For example Maruti has Engine, or House has Bathroom.

Let’s understand these concepts with an example of Car class.

 

http://www.w3resource.com/java-tutorial/inheritance-composition-relationship.php

 

分享到:
评论

相关推荐

    Data Fusion- Concepts and Ideas

    Examples and Matlab code now appear on a gray background for easy identification and advancd material is marked with an asterisk. The book is intended to be self-contained. No previous knowledge of ...

    英文原版-Sedentary Behavior and Health 1st Edition

    Though lack of exercise has major health consequences, researchers are now examining the additional and widespread health risk of the simple act of sitting for extended periods. With research from ...

    人工智能-机器学习-试论人机关系的历史发展及其文化考量.pdf

    This evolution has led to a situation where the world is increasingly shaped by machine-driven rules and norms, creating a "machine culture" that parallels human culture. As machines become more ...

    SQLMemTable for Delphi / C++ Builder

    SQLMemTable does not require BDE and provides all the TTable‘s functionssuch as Master/Detail relationship, Filtering, Searching, Sorting, Key, Range, BLOB fields, and has some advanced features ...

    NIST SP800-160-vol2-draft.pdf

    NIST Special Publication 800-160, Volume 2 focuses on the property of cyber resiliency, which has a strong relationship to security and resilience, but which provides a distinctive framework for its ...

    微软内部资料-SQL性能优化2

    A stack is an area of memory in which program procedure or function call addresses and parameters are temporarily stored. In Process To run in the same address space. In-process servers are loaded ...

    Pattern Recognition using Neural and Functional Networks(Springer2009新书)

    Each type has its specific advantages and is suited for different tasks. - **Applications in Pattern Recognition**: - **Image Recognition**: CNNs are particularly effective for recognizing patterns...

    Computer Security: Art and Science

    This is a textbook intended for use at the advanced undergraduate and introductory graduate levels, non-University training courses, as well as reference and self-study for security professionals....

    The geometry of multiple images.pdf

    The ideas generated, however, can be used indifferent settings, resulting in a general book on computer vision that reveals the fascinating relationship of three-dimensional geometry and the imaging ...

    i-vector的工具箱

    A total variability subspace is learned from the development set and is used to estimate a low (and fixed) dimensional latent factor called the identity vector (i-vector) from adapted mean ...

    Matlab-project.rar_R and MATLAB_inverse poly

    If c has n+1 components, the polynomial it represents is . Tips Note the relationship of this function to p = poly(r), which returns a row vector whose elements are the coefficients of the polynomial...

    WinHTTP WebSocket 代码

    Its only relationship to HTTP is that its handshake is interpreted by HTTP servers as an Upgrade request. The WebSocket protocol makes possible more interaction between a browser and a web site, ...

    博士研究生英语精读-翻译与原文(中科院).doc

    As we learn more about the human brain, for example, we face new challenges in understanding the nature of consciousness and the relationship between mind and body. In the arts and humanities, the ...

    Database Processing Fundamentals, Design, and Implementation (12th Edition).rar

    A Database Has Data and Relationships Databases Create Information Database Examples Single-User Database Applications Multiuser Database Applications E-Commerce Database Applications Reporting and ...

    Addison.Wesley.-.Imperfect.C++.Practical.Solutions.for.Real-Life.Programming.chm

    Matthew Wilson has been working with it for over a decade, and during that time he has found inherent limitations that require skillful workarounds. In this book, he doesn't just tell you what's ...

    Beginning WF: Windows Workflow in .NET 4.0

    He has extensive experience in retail (point-of-sale and inventory) and customer relationship management (CRM) solutions. Mark currently serves as a senior software engineer for a nonprofit ...

Global site tag (gtag.js) - Google Analytics