Week 13: Support for Object-Oriented Programming & Week 12: Abstract Data Types and Encapsulation

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/67

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

68 Terms

1
New cards

The major language features of OOP:

abstract data types, inheritance, and polymorphism

2
New cards

With inheritance, productivity increases can come from

reuse

3
New cards

Inheritance allows new classes to be

defined in terms of existing ones.

4
New cards

inheritance addresses both of these concerns:

reuse ADTs after minor changes and define classes in a hierachy

5
New cards

ADTs are usually called

classes

6
New cards

Class instances are called

objects

7
New cards

a class that inherits is a

derived class or a subclass

8
New cards

The class from which one another class inherits is a

parent class or superclass

9
New cards

Subprograms that define operations on objects are called

methods

10
New cards

Calls to methods are called

messages

11
New cards

The entire collection of methods of an object is called its

message protocol or message interface

12
New cards

Messages of two parts

a method name and the destination object

13
New cards

In the simplest case, a class inherits

all of the entities of its parent

14
New cards

Inheritance can be complicated by access controls to encapsulated entities. Examples of this are:

  1. A class can hide entities from its subclasses

  2. A class can hide entities from its clients

  3. A class can also hide entities for its clients while allowing its subclasses to

    see them

15
New cards

Besides inheriting methods as is, a class can modify an inherited method by:

  1. The new one overrides the inherited one

  2. The method in the parent is overriden

16
New cards

Three ways a class can differ from its parent:

  1. The subclass can add variables and/or methods to those inherited from the

    parent

  2. The subclass can modify the behavior of one or more of its inherited methods.

  3. The parent class can define some of its variables or methods to have private

    access, which means they will not be visible in the subclass

17
New cards

There are two kinds of variables in a class:

  1. class variables (one/class)

  2. instance variables (one/object)

18
New cards

There are two kinds of methods in a class:

  1. Class methods - accept messages to the class

  2. instance methods - accept messages to objects

19
New cards

One disadvantage of inheritance for reuse:

creates interdependencies among classes that complicate maintenance

20
New cards

a polymorphic variable can be defined in a class that is able to

reference (or point to) objects of the class and objects of any of its descendants

21
New cards

When a class hierarchy includes classes that override methods and such methods are called through a polymorphic variable…

the binding to the correct method will be dynamic

22
New cards

dynamic binding allows software systems to be more

easily extended during both development and maintenance

23
New cards

An abstract method is

one that does not include a definition (it only defines a protocol)

24
New cards

an abstract class is

one that includes at least one abstract method

25
New cards

an abstract class

cannot be instantiated

26
New cards

What are the design issues for object-oriented programming languages?

  1. The Exclusivity of Objects

  2. Are Subclasses Subtypes?

  3. Single and Multiple Inheritance

  4. Object Allocation and Deallocation

  5. Dynamic and Static Binding

  6. Nested Classes

  7. Initialization of Objects

27
New cards

With the exclusivity of objects

  1. everything is an object

  2. it adds objects to a complete typing system

  3. Includes an imperative-style typing system for primitives but makes everything else objects.

28
New cards

if a derived class is-a parent class, then

objects of the derived class must behave the same as the parent class object

29
New cards

A derived class is a subtype if it has

an is-a relationship with its parent class

30
New cards

subclass can only do what?

add variables and methods and override inherited methods in “compatible” ways

31
New cards

Subclasses inherit implementation; subtypes inherit

interface and behavior

32
New cards

Multiple inheritance allows

a new class to inherit from two or more classes

33
New cards

Disadvantages of multiple inheritance:

  1. Language and implementation complexity (in part due to name collisions)

  2. Potential inefficiency - dynamic binding costs more with multiple inheritance (but not much)

34
New cards

Advantage of multiple inheritance

sometimes it is quite convenient and valuable

35
New cards

If objects behave like ADTs, they can be allocated from

anywhere (run-time stack or explicitly create on the heap)

36
New cards

if the objects are all heap-dynamic, references can be uniform through

a pointer reference variable

37
New cards

if objects are stack dynamic, there is a problem with regard to

subtypes - object slicing

38
New cards

what is the use for scope resolution operator ( :: )?

a member that is not accessible in a subclass (due to private derivation) can be declared to be visible using this.

39
New cards

smalltalk is a pure

OOP language

40
New cards

In SmallTalk

  1. everything is an object

  2. all objects have local memory

  3. all computation is through objects sending messages to objects

  4. none of the appearances of imperative languages

  5. all objected are allocated from the heap

  6. all deallocation is implicit

41
New cards

Smalltalk classes cannot be

nested in other classes

42
New cards

SmallTalk Inheritance

  1. a subclass inherits all of the instance variables, instance methods, and class methods of its superclass

  2. all subclasses are subtypes

  3. all inheritance is implementation inheritance

  4. no multiple inheritance

43
New cards

SmallTalk Dynamic Binding

all binding of messages to methods is dynamic.

44
New cards

Process of binding messages to methods for SmallTalk

search the object to which the message is sent for the method. if not found, search the superclass etc. up to the system class which has no superclass

45
New cards

Evaluation of Smalltalk

  1. The syntax of the language is simple and regular

  2. Good example of power provided by a small language

  3. Slow compared with conventional compiled imperative languages

  4. Dynamic binding allows type errors to go undetected until run time

  5. Introduced the graphical user interface

  6. Greatest impact: advancement of OOP

46
New cards

Support for OOP in C++ Inheritance

  1. A class need not be the subclass of any class

  2. Access controls for members are private, public, and protected

47
New cards

Access controls: Private

visible only in the class and friends) (disallows subclasses from being subtypes

48
New cards

Access controls: Public

visible in subclasses and clients

49
New cards

Access controls: Protected

visible in the class and in subclasses, but not clients

50
New cards

Private derivation:

inherited public and protected members are private in the subclasses

51
New cards

Public derivation

public and protected members are also public and protected in subclasses

52
New cards

An abstraction is

a view or representation of an entity that includes only the most significant attributes

53
New cards

An abstract data type is

is a user-defined data type that satisfies two conditions

54
New cards

Two conditions for abstract data types

  1. The representation of objects of the type is hidden from the program

    units that use these objects

  2. The declarations of the type and the protocols of the operations on objects of the type are contained in a single syntactic unit. Other program units are allowed to create variables of the defined type

55
New cards

Advantages of Data Abstraction: First condition

  1. Reliability

  2. Reduces the range of code and variables of which the programmer must be aware

  3. Name conflicts are less likely

56
New cards

Advantages of Data Abstraction: Second condition

  1. Provides a method of program organization

  2. Aids modifiability (everything associated with a data structure is together), and

  3. Separate compilation

57
New cards

Language requirements for ADTs

  1. A syntactic unit in which to encapsulate the type definition

  2. A method of making type names and subprogram headers visible to

    clients, while hiding actual definitions

  3. Some primitive operations must be built into the language processor

58
New cards

ADTs in C++

  1. The class is the encapsulation device

  2. A class is a type

  3. All of the class instances of a class share a single copy of the

    member functions

  4. Each instance of a class has its own copy of the class data members

  5. Instances can be static, stack dynamic, or heap dynamic

59
New cards

Information Hiding: Private Clause

for hidden entities

60
New cards

Information Hiding: Public Clause

for interface entities

61
New cards

Information Hiding: Protected Clause

for inheritance

62
New cards

Friend functions or classes

to provide access to private members to some unrelated units or functions

63
New cards

Parameterized ADTs allow

designing an ADT that can store any type elements – only an issue for static typed languages (also known as generic classes)

64
New cards

Encapsulation Constructs

a grouping of subprograms that are logically related into a unit that can be separately compiled (compilation units)

65
New cards

A naming encapsulation is used to

create a new scope for names

66
New cards

C++ Namespaces

  1. Can place each library in its own namespace and qualify names used outsid with the namespace

  2. C# also includes namespaces

67
New cards

Java Packages

  1. Packages can contain more than one class definition; classes in a package are partial friends

  2. Clients of a package can use fully qualified name or use the import declaration

68
New cards

Ruby Modules (Naming Encapsulations)

  1. Ruby classes are name encapsulations, but Ruby

    also has modules

  2. Typically encapsulate collections of constants and

    methods

  3. Modules cannot be instantiated or subclassed, and

    they cannot define variables

  4. Methods defined in a module must include the

    module’s name

  5. Access to the contents of a module is requested

    with the require method