Chapter 3: Object-orientated programming Flashcards

(58 cards)

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
Instance variable
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
The process behind invocation of a constructor:
Java automatically: - Allocates memory space for the object - Invokes the constructor code to initialize the instance variables - Returns a reference to the object
27
3 Types of variables
- Argument variables - Local variables - Instance variables
28
Encapsulation
The process of separating clients from implementations by hiding information.
29
3 Reasons for encapsulation
- Enables modular programming - Facilitates debugging - Clarifies program code
30
Wide interface
An interface with an excessive number of methods.
31
Techniques to reduce the effective width of an interface
- Use overloading to provide implementations of basic methods for all types of data - Include methods that are orthogonal in functionality
32
Basic mantra for data types
Whenever possible, clearly separate data and associated operations within a program.
33
Primary value of API
They allow client code to ignore a substantial amount of detail found in the standard representations of these abstractions.
34
Java support for enforcing encapsulation
The private visibility modifier
35
Value of encapsulation enabling modular programming
Allows us to: - Independently develop of client and implementation code - Substitute improved implementations without affecting clients. - Support programs not yet written
36
Value of encapsulation isolating data-type operations:
Leads to the possibility of: - Adding consistency checks and other debugging tools in implementations - Clarifying client code
37
Immutable data type
The property that the value of the object never changes once constructed.
38
Mutable data type
Manipulates object values that are intended to change.
39
Purpose of immutable types
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
Purpose of mutable types
To encapsulate values as they change.
41
Advantages of immutability
- Easier to use | - Less misuse (smaller scope of code to change their values)
42
Cost of immutability
A new object must be created for every type.
43
Java support for enforcing immutability
The final modifier
44
Final modifier
The object can only be assigned a value once, either in an initializer or in the constructor.
45
Inheritance
Support for defining relationships among objects.
46
Interfaces
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
Subtyping
``` 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
Subclass
``` A Class that inherits instance variables and instance methods from another class - its superclass. The subclass contains more methods than its superclass. ```
49
Two reasons subtyping makes modular programming difficult:
- 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
Fragile base class problem
A state where the subclass cannot be developed independently of the superclass as it is completely dependent on its superclass.
51
Data mingin
The process of searching through the massive amounts of information now accessible to every user on the web.
52
Assertion
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
Purpose of assertions
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
Design-by-contract programming model
``` 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
Precondition
The condition that the client promises to satisfy when calling a method.
56
Postcondition
The condition that the implementation promises to achieve when returning from a method.
57
Invariants
Any condition that the implementation promises to satisfy while the method is executing
58
Side effects
Any other change in state that the method could cause.