Week 10- Abstract Data Types and Encapsulation Flashcards

1
Q

What are the three types of member clauses in C++ for information hiding?

A

Private, public, and protected clauses.

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

What are some design issues for ADTs?

A

Form of the container for the interface.
Parameterization of abstract types.
Access controls provided.
Physical separation of specification from implementation.

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

What is process abstraction?

A

Process abstraction involves subprograms where nearly all programming languages support it. For example, when sorting a list, the specific sorting algorithm (merge, quick, select, insertion) is abstracted away.

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

What are the advantages of hiding data in ADTs?

A

Reliability, Reduced Complexity, Reduced Name Conflicts, Modifiability: Client code does not need to change if the implementation changes.

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

What is data abstraction?

A

Data abstraction involves the use of record types and includes subprograms that manipulate data, with access controls to hide details.

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

How can data members be accessed in ADTs?

A

Indirectly via getters and setters. Read-only versions can be provided by only offering getters, and setters can enforce constraints.

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

What is a key feature of a stack ADT?

A

A stack allows access to the data element at the top only, typically using the pop() operation as a getter.

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

How are getter and setter methods used to access data members in C#?

A

Getter and setter methods in C# are used through properties, allowing implementation of getters and setters without explicit method calls.

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

What is the name of a destructor in C++ and how is it distinguished?

A

A destructor’s name is the same as the class name, preceded by a tilde (~).

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

What is a property in C#?

A

A property in C# allows encapsulation of a class’s data members, providing a way to access and modify the private fields using getters and setters without explicit method calls.

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

What is the primary purpose of constructors in C++?

A

Constructors in C++ are used to initialize the data members; they don’t create objects.

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

How do instances of a class in C++ handle member functions and data members?

A

All instances of a class share a copy of member functions (methods), but each instance has its own copy of class data members (instance variables).

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

Describe the significance of friend functions or classes in C++.

A

Friend functions or classes allow access to private members from unrelated units and must be declared inside a class.

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

What is the significance of the StackClass example provided for Java?

A

It illustrates how to implement a stack using Java, demonstrating constructors, methods for stack operations (push, pop, top, empty), and access control.

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

Provide an example of how to use a property to access an instance variable bar in an instance foo.

A

a = foo.bar; // getter
foo.bar = 3.5; // setter

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

Differentiate between local variables, instance variables, and class variables in Ruby.

A

Local variables: regular identifiers.
Instance variables: begin with @.
Class variables: begin with @@.

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

What are the two primary features of Abstract Data Types (ADTs)?

A

The two primary features of ADTs are the packaging of data with their associated operations and information hiding.

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

What are the three major language features of OOP?

A

The three major language features of OOP are abstract data types, inheritance, and polymorphism.

14
Q

How does inheritance improve productivity in OOP?

A

Inheritance allows new classes to be defined in terms of existing ones, enabling reuse of ADTs with minor changes and defining classes in a hierarchy.

15
Q

What are subclasses and how do they relate to parent classes?

A

Subclasses, or derived classes, inherit from parent (superclass) classes. They can add new variables and methods, modify inherited methods, and hide some inherited entities.

16
Q

What are the two kinds of variables in a class?

A

The two kinds of variables in a class are class variables (one per class) and instance variables (one per object).

17
Q

What are the two kinds of methods in a class?

A

The two kinds of methods in a class are class methods (accept messages to the class) and instance methods (accept messages to objects).

18
Q

What is the difference between single inheritance and multiple inheritance?

A

Single inheritance allows a class to inherit from only one parent class, while multiple inheritance allows a class to inherit from multiple parent classes, which can lead to conflicts and interdependencies among classes.

19
Q

What is dynamic binding and how does it relate to polymorphism?

A

Dynamic binding allows the method of a subclass to override a parent’s method, with the specific method being called determined at run-time. This supports polymorphism, allowing polymorphic variables to hold objects of a class or any of its descendants.

20
Q

What is an abstract (virtual) method and an abstract class?

A

An abstract (virtual) method defines a protocol without a definition, and an abstract class includes at least one abstract method and cannot be instantiated.

21
Q

List some of the design issues for OOP languages.

A

Some design issues for OOP languages include:
Whether everything is an object (exclusivity of objects)
Whether subclasses are subtypes
Whether the language supports single or multiple inheritance
How objects are allocated and deallocated
The use of dynamic and static binding
The presence of nested classes
How objects are initialized

22
Q

What is the advantage of having everything as an object?

A

The advantage is the elegance, purity, and homogeneity of all data structures.

23
Q

What is the disadvantage of having everything as an object?

A

The disadvantage is that it can be slow for simple objects.

24
Q

In most object-oriented languages, are subclasses considered subtypes?

A

Yes, most OO languages consider subclasses as subtypes.

25
Q

What does it mean for a subclass to be a subtype of its parent class?

A

It means that an “isa” relationship holds between the parent class and subclass, and instances of the subclass must behave similarly to instances of the parent class.

26
Q

What can a subclass do in relation to its parent class?

A

A subclass can add variables and methods, and override methods in compatible ways.

27
Q

Why are subclasses created according to ontological reasons?

A

Subclasses are made for ontological reasons, not just for functionality and reuse, to ensure the hierarchy makes sense conceptually (e.g., making an airplane a subclass of a vehicle rather than a bird).

28
Q

What are the advantages of multiple inheritance?

A

The advantages include convenience (methods and variables from multiple sources) and ontological usefulness (e.g., an aircraft can be both a vehicle and a flying object).

29
Q

What are the disadvantages of multiple inheritance?

A

The disadvantages include increased complexity in the language and implementation, handling name collisions, and potential inefficiency due to increased cost of dynamic binding.

30
Q

Where can objects be allocated if they are treated as other ADTs?

A

They can be allocated anywhere, such as the run-time stack or heap.

31
Q

Where are objects allocated if they are heap-dynamic only?

A

They are allocated on the heap.

32
Q

What are the benefits of allocating objects on the heap?

A

References can be uniform via pointer/reference variables, simplifying assignment and allowing implicit dereferencing.

33
Q

What issues can arise with stack-dynamic object allocation?

A

Stack-dynamic allocation can lead to object slicing, where an instance of a subclass may not have enough room allocated when passed to a subroutine expecting an instance of the parent class.

34
Q

Is object deallocation typically explicit or implicit?

A

Deallocation can be either explicit or implicit, depending on the language.

35
Q

Should all binding of messages to methods be dynamic?

A

It depends. If none are dynamic, the advantages of dynamic binding are lost. If all are dynamic, it can be inefficient. A design may allow the user to specify.

36
Q

Why might a nested class be useful?

A

Nested classes are useful to avoid cluttering the object system, prevent name clashes, and keep related classes together, such as defining a Node class within a Tree class.

37
Q

Are objects initialized to values when they are created?

A

This depends on the language. Initialization can be implicit or explicit.

38
Q

How are parent class members initialized when a subclass object is created?

A

The initialization process for parent class members when a subclass object is created varies by language and typically involves calling the parent class’s constructor.