Week 2 - Object Concepts Flashcards

1
Q

Based on unit 1, how would you describe an object?

A

Unit 1 describes an object as a self-contained unit of software that holds data and understands a set of messages that may cause it to perform behaviours such as changing state. Each object is able to communicate with other objects via messages.

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

Why is it better to reuse classes, the basis of OOP?

A

It is more economical leads to less mistakes and saves time.

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

In your own words, what does it mean to say that an instance of a class is intialised?

A

Instances of a class have attributes. It is usual for a newly created object to have its attributes initialised to some initial values.

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

What is a subclass and what is a superclass?

A

a subclass is a class that is derived from the protocls and attributes of another class which is then called the superclass.

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

What is inheritance?

A

It is the relationship between a subclass and its superclass, a subclass is said to inherit the attributes and the protocol from the superclass.

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

What criteria do you think the programmer has applied in deciding to create the cl;ass HoverFrog as a subclass of the class Frog?

A

The programmer required the instances of the class HoverFrog to have all the attributes of the class Frog, to understand all the messages that instances of the class Frog understand, and to behave in an identical way in response to most of these messages.

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

What is the message name in each of the following?

a) setColour(OUColour.YELLOW)
b) jump()
c) frog1.setColour(OUColour.BROWN)
d) hoverfrog2.green()

A

a) setColour()
b) jump()
c) setColour()
d) green()

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

In general, what is the difference between a message and a message name? What is the difference between a message and a message name when the message has no arguments?

A

A message name is the textual form of a message except that any arguments it takes are not shown. If a message takes no arguments the message and its name will be indistinguishable.

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

What is the message name in each of the following?

a) oldBicycle.remove(bell)
b) oldBicycle.install(bell, newBicycle)

A

a) remove()

b) install()

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

When the argument object and the receiver are collaborating, what is happening?

A

When one object(frog7, for example) is used as an argument in a message to another object (frog6, for example) we say that the argument object and the receiver are collaborating.

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

What is a getter message?

A

a getter message or an accessor message is a message that gets (returns) an attribute value, because it allows you to access information about an object.

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

What is a setter message?

A

a setter message or a mutator message, is a message that is intended to change the state of an object.

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

What, if anything, is returned as the message when the following message is sent to a Frog object that is brown?

a) getColour()
b) setColour(OUColour.RED)

A

a) OUColour.BROWN

b) no answer is returned.

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

In summary what is a class?

A

A class describes a group of objects that the programmer considers to be similar. Instances of the same class understand the same set of messages (their protocol), have the same attributes and behave in the same way in response to each message.

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

What is the receiver?

A

The receiver is the object to which a message will be sent.

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

What happens if you send a message to an object that does not have that message in its protocol?

A

A message must be in the protocol of the receiver, otherwise a statement attempting to send such a message cannot be executed.

17
Q

A message may:

a) change the state of an object
b) make an object do something without changing its state
c) get back some useful information from an object
d) cause an object to send a message to another object
e) cause an object to send a message to itself.

give examples.

A

a) left()
b) jump()
c) getColour()
d) frog1.sameColourAs(frog2) - the receiver sends getColour() to frog2
e) in response to frog1.sameColourAs(frog2) the receiver frog1 changes its own colour. The name of the message sent is setColour().

18
Q
Fill in the following table for the message-send
herAccount.transfer(myAccount, 200)
Receiver
Message
Message Name
Argument(s)
Message-send
A
R - herAccount
M - transfer(myAccount, 200)
MN - transfer()
A - myAccount, 200
MS - herAccount.transfer(myAccount,200)
19
Q

Decide whether each of the following statements is true or false. If false, say why.

a) All messages consist of a name an argument.
b) An object is associated with a particular class.
c) A message is an instance of a class.

A

a) False. Some messages have no arguments, some have more than one argument.
b) true
c) False. Messages are not objects, and so they are not instances of a class.