OO Relationships (PPT 11 - 13) Flashcards

1
Q

What is a relationship?

A

Collaboration between objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is an association relationship?

A

Association represents a link/memory between objects. Messages may flow in either direction across the association

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do we name an association?

A

It is stated in terms of the objects being associated. The combination of objects and association name should read like a sentence

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How many associations can an object have?

A

It can have as many as it wants and can also have as many associations between objects as you want

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a reflexive association?

A

Associations which involve only one class of object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are role names?

A

Used to indicate the role performed by each end of the association

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is multiplicity?

A

The number of instances of objects which may be involved at either end of the association

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a composition relationship?

A

It is a stronger form of association, relates a whole object to its parts. Represented by a line with a filled in diamond on the end. Idea is one object is either physically part of another or is exclusively owned by another one

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a aggregation relationship?

A

It is a slightly weaker form of composition. Means a part may outlive the whole it is part of. The owner only has temporary ownership, not exclusive ownership

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a dependency?

A

Where objects come into temporary contact with each other during the running of the program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do we know if we need a relationship?

A
  • If one class creates an instance of another one
  • If one class received an instance of another on as input to a method/function
  • If one class has an instance of another one as one of its fields/attributes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a uni-directional association?

A

Messages only travel in one direction. Helps protect coupling and reuse

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a generalisation?

A

Relationship between a general concept and its more specific forms. Allows parent child hierarchies

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a superclass?

A

It is a class which represents a general concept. Defines characteristics and behaviours expected of any type of this class, e.g. shape

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does a subclass inherit?

A

It automatically inherits all characteristics and behaviour from it parent

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the difference between Generalisation and Specialisation?

A

Generalisation

  • From the bottom up
  • Uses superclass

Specialisation

  • Top down
  • Usually apparent in the application domain
17
Q

What are the golden rules of inheritance?

A
  • Must model as a is-a relationship

- Child concept remains the same for its lifetime

18
Q

What is polymorphism?

A

Any instance of a child class can be used anywhere an instance of the parent is expected

19
Q

What is overriding?

A

A child class may refine or replace a feature inherited from a parent class by defining a feature with the same name

20
Q

What is an abstract class?

A

It is a class which is an abstract concept, such as a shape

21
Q

What is an interface?

A

A construct to specify a common piece of behaviour required by a system. No implementation is provided, another class has to implement the operations

22
Q

What are the differences between abstract and interface classes?

A

Abstract class are what an object is while interface is what an object does
Identifying
-Abstract: usual inheritance rules apply
-Interface: when disparate concepts wish to provide the same behaviour

Structure

  • Abstract:define attributes, operations, relationships
  • Interface: define operations only
23
Q

What are some dangers with Inheritance?

A
  • Inheritance may create fragile hierarchies (changes to a parent can ripple throughout the code)
  • Inheritance is said to provide weak encapsulation (parent class has direct access to innards of child class)