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.