今天在SCJP的试题中看见关于‘is a relationship’ ,‘has a relationship’的试题,一开始没搞清楚怎么回事,就google了一下,找到如下文章,觉得挺有用的。跟大家分享下啊。
what is 'is a' and 'has a' relationship:
The ‘is a relationship’ is expressed with inheritance and ‘has a relationship’ is expressed with composition.
Both inheritance and composition allow you to place sub-objects inside your new class. Two of the main techniques for code reuse are class inheritance and object composition.
e.g.,
is a --- House is a Building
class Building {
.......
}
class House extends Building {
.........
}
has a -- House has a bathroom
class House
{
Bathroom room = new Bathroom() ;
....
public void getTotMirrors()
{
room.getNoMirrors();
....
}
}
Inheritance Vs Composition
Inheritance is uni-directional. For example House is a Building. But Building is not a House. Inheritance uses
‘extends’ key word. Composition: is used when House has a Bathroom. It is incorrect to say House is a Bathroom.
Composition simply means using instance variables that refer to other objects. The class House will have an instance variable, which refers to a Bathroom object.
分享到:
相关推荐
In an ER model, the cardinality ratio of a relationship type is (a) the number of instances of relationships of that relationship type (b) the number of entity types involved in that relationship ...
Has-a-relationship
Advancements in technology have made relationship marketing a reality in recent years. Technologies such as data warehousing, data mining, and campaign management software have made customer ...
The entity-relationship model toward a unified view of data 论文
关于E-R模型的论文,是美籍华裔计算机科学家peter.chen写的。
6.please explain the relationship between classpath and package,and the relationship between them and java files. 7.what is the differense session Bean and Entity Bean ? 8.please write out the meaning...
非常有用的哦 是Application of data mining techniques in customer relationship managemen
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.
This chapter answers the question “What is a .NET Compact Framework application?” in two ways: by studying the details of a simple, but complete, Compact Framework Windows application. Along the ...
Our Social Relationship Graph Generation Network (SRG-GN) is the first to use memory cells like Gated Recurrent Units (GRUs) to iteratively update the social relationship states in a graph using ...
ArcGIS Geodatabase RelationshipClass
Onlyoffice服务调用Demo-...ONLYOFFICE CommunityServer is a free open source collaborative system developed to managedocuments, projects, customer relationship and email correspondence, all in oneplace.
SAPSRM (over view)SAP Supplier Relationship Management (Col92)
32 Why is it always hard to handle the relationship b.docx
Special education classification and program success: Is there a relationship? Psychology in the Schools Volume 28. October 1991 SPECIAL EDUCATION CLASSIFICATION AND PROGRAM SUCCESS: IS THERE ...
This system is a role-based rights management, buddy relationship, group relations social network system, written in php, framework initp… 软件开发设计:应用软件开发、系统软件开发、移动应用开发、网站...
Modeling Mutual Visibility Relationship in Pedestrian Detection Modeling Mutual Visibility Relationship in Pedestrian Detection Modeling Mutual Visibility Relationship in Pedestrian Detection
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 ...
A model of customer relationship management and business intelligence systems for catalogue and online retailers
Data modeling and database design have undergone significant evolution ...systems, using the ER (entity relationship) approach for conceptual modeling (solely a logical implementation).