`
oywl2008
  • 浏览: 1000895 次
  • 性别: 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

 

分享到:
评论

相关推荐

    michael-jordan-a-biography-greenwood-biographies.pdf

    With the possible exceptions of boxer Muhammad Ali and baseball player Babe Ruth, no athlete has made a greater impact on American society-or in the world-than Michael Jordan. Follow the life of one ...

    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 ...

    Intensity and Edge-Based Symmetry Detection Applied to Car-Following

    A symmetry finder has been developed which uses the intensity-based method to search an image for compact regions which display some degree of mirror symmetry due to intensity similarities across a ...

    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 ...

    Knowledge Transfer between Computer Vision and Text Mining: Similarity-based

    pairwise relationship can be either a similarity, a dissimilarity, or a distance function. This book studies several similarity-based learning approaches, such as nearest neighbor models, local ...

    A structural equation modeling (SEM) approach

    confirm that good governance has a significant and positive impact on the relationship between managerial roles and development roles to the personal development of public sector managers.

    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 ...

    PhD thesis

    (2) the structure of normal contact force inside a horizontal slug has a uniform, non-uniform, and uniform distributions in turn in the axial direction when the slug achieves a stable state from a ...

    微软内部资料-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 ...

    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 ...

    A Design Methodology for Highly-Integrated Low-Power Receivers for Wireless Communications

    historically unilateral relationship between system designers and hardware designers. An efficient solution requires a design strategy which tightly incorporates implementation issues throughout the ...

    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 ...

    Inbound Marketing Get Found Using Google, Social Media, and Blogs

    and the National Canned Spam Act limits a mar keter's ability to send "unsolicited messages" to people with whom the company does not have a relationship. Accord ing to the research firm ...

    A STUDY INTO THE FOUNDATIONS OF CRM SUCCESS

    Customer Relationship Management is a topic that has attracted the attention of both marketing practitioners and researchers over the last decade. Despite, or maybe due to, the attention drawn to ...

    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, ...

    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 ...

Global site tag (gtag.js) - Google Analytics