Chapter 3: Object-orientated programming Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Object

A

An entity that can take on a data-type value.

An instance of a data type.

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

Data abstraction

A

The ability to define new data types and to manipulate objects holding data-type values.

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

8 Primitive data types

A
  • boolean
  • byte
  • char
  • double
  • float
  • int
  • long
  • short
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Data type

A

A set of values and a set of operations defined on those values.

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

API

A

Application programming interface

A document whose purpose is to provide the information needed to write programs using the data type.

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

Constructor

A

Creates an object and returns to the client a reference to the object, not the object itself.

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

Identity

A

The memory space associated with the object.

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

Pointer

A

An object whose value refers directly to another value stored elsewhere in the computer memory using its address.

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

Uninitialized variable

A

A variable that has been declared of a reference type but has not been assigned a value.

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

3 Essential properties of objects:

A
  • state
  • behavior
  • identity
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

State of an object

A

A value from its data type.

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

Behavior of an object

A

Defined by the data type’s operations.

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

Identity of an object

A

The place where the object is stored in memory.

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

What is used to create objects in OOP?

A

constructors are invoked

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

How are object states modified in OOP?

A

instance methods are invoked

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

Assignment statement

A

A statement that creates a second copy of a reference.

It does not create a new object, just another reference to an existing object.

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

Aliasing

A

The situation where assignment statements don’t create a new object, but rather another reference to an existing object.

Both variables refer to the same object.

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

Immutable

A

A data type that has no methods that can change an objects’ value.

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

public entity

A

An entity that is accessible by clients

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

private entity

A

An entity that is not accessible by clients

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

final modifier

A

A modifier that indicates that the value of the variable will not change once it is initialized.

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

Convention to using public and private

A

public - Used for all methods and constructors in the API

private - everything else

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

Typical private methods

A

Helper methods, used to simplify code in other methods in the class.

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

Local variables

A

Variables to which there is just one value corresponding to each one at a given time

25
Q

Instance variable

A

Variables to which to which there are numerous values corresponding to each one at a given time (one for each object that is an instance of the data type).

26
Q

The process behind invocation of a constructor:

A

Java automatically:

  • Allocates memory space for the object
  • Invokes the constructor code to initialize the instance variables
  • Returns a reference to the object
27
Q

3 Types of variables

A
  • Argument variables
  • Local variables
  • Instance variables
28
Q

Encapsulation

A

The process of separating clients from implementations by hiding information.

29
Q

3 Reasons for encapsulation

A
  • Enables modular programming
  • Facilitates debugging
  • Clarifies program code
30
Q

Wide interface

A

An interface with an excessive number of methods.

31
Q

Techniques to reduce the effective width of an interface

A
  • Use overloading to provide implementations of basic methods for all types of data
  • Include methods that are orthogonal in functionality
32
Q

Basic mantra for data types

A

Whenever possible, clearly separate data and associated operations within a program.

33
Q

Primary value of API

A

They allow client code to ignore a substantial amount of detail found in the standard representations of these abstractions.

34
Q

Java support for enforcing encapsulation

A

The private visibility modifier

35
Q

Value of encapsulation enabling modular programming

A

Allows us to:

  • Independently develop of client and implementation code
  • Substitute improved implementations without affecting clients.
  • Support programs not yet written
36
Q

Value of encapsulation isolating data-type operations:

A

Leads to the possibility of:

  • Adding consistency checks and other debugging tools in implementations
  • Clarifying client code
37
Q

Immutable data type

A

The property that the value of the object never changes once constructed.

38
Q

Mutable data type

A

Manipulates object values that are intended to change.

39
Q

Purpose of immutable types

A

To encapsulate values that do not change so they behave in the same way as primitive types.

We can use them without having to worry about their values changing.

40
Q

Purpose of mutable types

A

To encapsulate values as they change.

41
Q

Advantages of immutability

A
  • Easier to use

- Less misuse (smaller scope of code to change their values)

42
Q

Cost of immutability

A

A new object must be created for every type.

43
Q

Java support for enforcing immutability

A

The final modifier

44
Q

Final modifier

A

The object can only be assigned a value once, either in an initializer or in the constructor.

45
Q

Inheritance

A

Support for defining relationships among objects.

46
Q

Interfaces

A

Provide a mechanism for specifying a relationship between otherwise unrelated classes, by specifying a set of common methods that each implementing class must contain.

47
Q

Subtyping

A
A powerful technique that enables a programmer to change the behavior of a class and add functionality without rewriting the entire class.
This is done by defining a subclass.
48
Q

Subclass

A
A Class that inherits instance variables and instance methods from another class - its superclass.
The subclass contains more methods than its superclass.
49
Q

Two reasons subtyping makes modular programming difficult:

A
  • Any change in the superclass affects all subclasses - the fragile base class problem
  • Subclass code - having access to instance variables - can subvert the intention of the superclass code.
50
Q

Fragile base class problem

A

A state where the subclass cannot be developed independently of the superclass as it is completely dependent on its superclass.

51
Q

Data mingin

A

The process of searching through the massive amounts of information now accessible to every user on the web.

52
Q

Assertion

A

A boolean expression that you are affirming is true at that point in the program.
If the expression is false, the program will terminate and report an error message.

53
Q

Purpose of assertions

A

They are widely used to detect bugs and gain confidence in the correctness of programs.
They also serve to document the programmer’s intent.

54
Q

Design-by-contract programming model

A
The designer expresses a:
- precondition
- postcondition
- invariats
- side effects
During development, these conditions can be tested with assertions (which can be used to aid in debugging).
55
Q

Precondition

A

The condition that the client promises to satisfy when calling a method.

56
Q

Postcondition

A

The condition that the implementation promises to achieve when returning from a method.

57
Q

Invariants

A

Any condition that the implementation promises to satisfy while the method is executing

58
Q

Side effects

A

Any other change in state that the method could cause.