Week 10- Abstract Data Types and Encapsulation Flashcards
What are the three types of member clauses in C++ for information hiding?
Private, public, and protected clauses.
What are some design issues for ADTs?
Form of the container for the interface.
Parameterization of abstract types.
Access controls provided.
Physical separation of specification from implementation.
What is process abstraction?
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.
What are the advantages of hiding data in ADTs?
Reliability, Reduced Complexity, Reduced Name Conflicts, Modifiability: Client code does not need to change if the implementation changes.
What is data abstraction?
Data abstraction involves the use of record types and includes subprograms that manipulate data, with access controls to hide details.
How can data members be accessed in ADTs?
Indirectly via getters and setters. Read-only versions can be provided by only offering getters, and setters can enforce constraints.
What is a key feature of a stack ADT?
A stack allows access to the data element at the top only, typically using the pop() operation as a getter.
How are getter and setter methods used to access data members in C#?
Getter and setter methods in C# are used through properties, allowing implementation of getters and setters without explicit method calls.
What is the name of a destructor in C++ and how is it distinguished?
A destructor’s name is the same as the class name, preceded by a tilde (~).
What is a property in C#?
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.
What is the primary purpose of constructors in C++?
Constructors in C++ are used to initialize the data members; they don’t create objects.
How do instances of a class in C++ handle member functions and data members?
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).
Describe the significance of friend functions or classes in C++.
Friend functions or classes allow access to private members from unrelated units and must be declared inside a class.
What is the significance of the StackClass example provided for Java?
It illustrates how to implement a stack using Java, demonstrating constructors, methods for stack operations (push, pop, top, empty), and access control.
Provide an example of how to use a property to access an instance variable bar in an instance foo.
a = foo.bar; // getter
foo.bar = 3.5; // setter
Differentiate between local variables, instance variables, and class variables in Ruby.
Local variables: regular identifiers.
Instance variables: begin with @.
Class variables: begin with @@.
What are the two primary features of Abstract Data Types (ADTs)?
The two primary features of ADTs are the packaging of data with their associated operations and information hiding.
What are the three major language features of OOP?
The three major language features of OOP are abstract data types, inheritance, and polymorphism.
How does inheritance improve productivity in OOP?
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.
What are subclasses and how do they relate to parent classes?
Subclasses, or derived classes, inherit from parent (superclass) classes. They can add new variables and methods, modify inherited methods, and hide some inherited entities.
What are the two kinds of variables in a class?
The two kinds of variables in a class are class variables (one per class) and instance variables (one per object).
What are the two kinds of methods in a class?
The two kinds of methods in a class are class methods (accept messages to the class) and instance methods (accept messages to objects).
What is the difference between single inheritance and multiple inheritance?
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.
What is dynamic binding and how does it relate to polymorphism?
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.