Final Exam - Last of Semester Material

¡Supera tus tareas y exámenes ahora con Quizwiz!

What are the advantages of data abstraction with the first condition? condition #1: the representation of objects of the type is hidden from the program units that use these objects, so the only operations possible are those provided in the type's definition

1) Reliability >> by hiding the data representations, user code cannot directly access the objects of the type or depend on the representation, allowing the representation to be changed without affecting user code 2) Reduces the range of code and variables of which the programmer must be aware 3) Name conflicts are less likely

What are 3 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

Inheritance

1) Using the features of an existing class 2) more than one class will be involved 3) superclass: existing class from which features are used 4) subclass: new class that uses features of an existing class 5) relationship: "is-a

What are the language requirements for abstract data types (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

General characteristics of object oriented programming in Java

1) all data are objects except the primitive types 2) all primitive types have wrapper classes that store one data value 3) all objects are heap-dynamic, are referenced through reference variables, and most are allocated with new 4) a finalize method is implicitly called when garbage collector is about to reclaim the storage occupied by the object

What are 3 design issues for ADTs?

1) can abstract types be parameterized? 2) what access controls are provided? 3) is the specification of the type physically separate from its implementation?

The subclassing process can be declared with access controls (private or public), which define potential changes in access by subclasses. Describe the two types of derivations

1) private derivation >> inherited public and protected members are private in the subclasses 2) public derivation >> public and protected members are also public and protected in subclasses

What is a class that inherits called?

Derived class or a subclass

what is an abstract data type?

a user-defined data type that satisfies the following 2 conditions: 1) the representation of objects of the type is hidden from the program units that use these objects, so the only operations possible are those provided in the type's definition 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.

Describe the Java language:

• Similar to C++, except: 1) All user-defined types are classes 2) All objects are allocated from the heap and accessed through reference variables 3) Individual entities in classes have access control modifiers (public or private), rather than clauses 4) Implicit garbage collection of all objects (don't need a destructor) 5) Java has a second scoping mechanism (package scope), which can be used in place of friends. >> All entities in all classes in a package that do not have access to control modifiers are visible throughout the package

Summary of chapter 11 (ADTs & Encapsulation Concepts)

• The concept of ADTs and their use in design was a milestone in the development of languages • Two primary features of ADTs are the packaging of data with their associated operations and information hiding • C++'s data abstraction is provided by classes • Java's data abstraction is similar to C++ • C++, Java 5.0, and C# 2005: support parameterized ADTs • C++, Java, C#, and Ruby: provide naming encapsulations

dynamic binding in c++

• a method can be defined to be virtual • a pure virtual function has no definition at all

nested classes in java

• all are hidden from all classes in their package, except for the nesting class • nonstatic classes nested directly are called innerclasses >> an innerclass can access members of its nesting class >> a static nested class cannot access members of its nesting class • Nested classes can be anonymous • A local nested class is defined in a method of its nesting class >> no access specified is used

dynamic binding in java

• all messages are dynamically bound to methods, unless the method is final ex: it can't be overridden, therefore dynamic binding serves no purpose • static binding is also used if the method is static or private, both of which disallow overriding

what are general characteristics in C++ (for support for OOP)

• evolved from C and Simula 67 • among the most widely used OOP languages • Mixed typing system • constructors and destructors • Elaborate access controls to class entities

Should all binding of messages to methods be dynamic?

• if none are, you lose the advantages of dynamic binding • if all are, it is inefficient >> maybe the design should allow the user to specify

Inheritance in Java

• single inheritance supported only, but there is an abstract class category that provides some of the benefits of multiple inheritance (interface) • an interface can include only method declarations and some named constants • methods can be final (cannot be overridden) • all subclasses are subtypes

what is the importance like for the concept of abstraction in programming and computer science?

• the concept of abstraction is fundamental!! >> one of the core principles of object-oriented programming • nearly all programming languages support process abstraction with subprograms • nearly all programming languages designed since 1980 support data abstraction

What are friend functions or classes in C++?

• they provide access to private members to some unrelated units or functions • necessary in C++ Ex: setters and getters

what methods are called through a polymorphic variable?

• when a class hierarchy includes classes that override methods. >> these are the methods that are called through a polymorphic variable • the binding to the correct method will be dynamic • polymorphic variables allows software systems to be more easily extended during both development and maininance.

what does an object that is allocated from the stack look like?

Call a method: ex: object.method() instead of pointer: method()

What are ADTs usually called?

Classes

what is encapsulation

the definition of the ADT (or class) is all in one place - the class definition

Inheritance can be complicated by access controls to encapsulated entities

• A class can hide entities from its subclasses • A class can hide entities fro its clients • A class can also hide entities for tis clients while allowing its subclasses to see them

Describe the C++ language:

• Based on C struct type and Simula 68 classes • The class is the encapsulation device • A class is a type • All of the instances of a class share a single copy of the member functions • Each instance of a class has its own copy of the class data members • Instances can be static, stack dynamic, or heap dynamic

Describe parameterized ADTs in C++:

• C++ can provide support for parameterized ADTs • Classes can be somewhat generic by writing parameterized constructor functions •Element types can be parameterized by making the class a templated class >> ex: image

Encapsulation in C++

• Can define header and code files, similar to those of C or... • Classes can be used for encapsulation >> The class is used as the interface (prototypes) >> The member definitions are defined in a separate file friends provide a way to grand access to private members of a class

Evaluation

• Design decisions to support object oriented programming are similar to C++ • No support for procedural programming • No parentless classes • Dynamic binding is used as "normal" way to bind method calls to method definitions • Uses interfaces to provide simple form of support for multiple inheritance

Encapsulation in C

• Files containing one or more subprograms can be independently compiled • The interface is placed in a header file >> #include preprocessor specification is used to include header files in applications • Problem #1: the linker does not check types between a header and associated implementation • Problem #2: the inherit problems with pointers

Describe destructors in C++

• Functions to cleanup after an instance is destroyed >> Usually just to reclaim heap storage • Implicitly called when the object's lifetime ends • Can be explicitly called • Name is the class name, proceded by a tilde (~)

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

• The new one overrides the inherited one • The method in the parent is overridden

Productivity increases can come from reuse:

1) ADTs are difficult to reuse >> they always need changes 2) All ADTs are independent and at the same level

what are the 3 major language features (object orient programming)?

1) Abstract data types (ch11) 2) Inheritance - the central theme in OOP and languages that support it 3) Polymorphism

What are thw two kinds of variables in a class?

1) Class variables >> one / class 2) Instance variables >> one / object

3 characteristics of object oriented programming

1) data abstraction 2) encapsulation 3) information hiding

Describe the information hiding for C++

1) private - clause for hidden entities 2) public - clause for interface entities 3) protected - clause for inheritance

What are class instances called?

Objects

Single vs multiple inheritance

One disadvantage of inheritance for reuse: creates interdependencies among classes that complicate maintenance

what is the class from which another class inherits called?

Parent class or a superclass

Inheritance (support for OOP in C++)

a class need not be the subclass of any classes >> a class is a subclass of a larger class

abstract class

a class that has at least one pure virtual function

what is an abstraction?

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

What do parameterized ADTs allow?

allow designing an ADT that can store any type elements • only an issue for static-typed languages

what is information hiding?

class definition can ensure that the data members (i.e. properties or instance variables) aren't altered inappropriately by objects of a different class (with the use of public, protected, and private specifiers).

What are parameterized abstract data types also known as?

generic classes

What are subprograms that define operations on objects called?

methods

How does inheritance address the reuse concerns?

reuse ADTs after minor changes and define classes in a hierarchy

Describe constructors in C++

• Functions to initialize the data members of instances (they do not create the objects) • May also allocate storage if part of the object is heap-dyanmic • Can include parameters to provide parameterization of the objects • Implicitly called when an instance is created • Can be explicitly called • Name is the same as the class name

Abstract method (dynamic binding concepts)

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

what is data abstraction?

the user of the abstract data type (or class) knows only parts of the ADT and the methods that can be executed >> you don't know how the methods are executed, and you don't need to know. >> you just NEED to know, for the methods, the parameters of the methods and the type of the return value (and a general description in words of what the method will do).

Describe classes in Java 5.0:

• Java 5.0 can provide support for parameterized ADTs • Generic parameters must be classes >> Most common generic types are the collection types (ex: LikedList, ArrayList) • Eliminate the need to cast objects that are removed • Eliminate the problem of having multiple types in a structure • Users can define generic classes • Generic collection classes can't store primitives • Indexing is not supported Ex of the use of a predefined generic class: ArrayList <Integer> myArray = new ArrayList <Integer> (); myArray.add(0, 47); // Put an element with subscript 0 in it Ex of the class: >> image

For inheritance in C++, what are the access controls for members?

1) Private - visible only to the class and friends (disallows subclasses from being subtypes) 2) Public - visible in subclasses and clients 3) Protected - visible in the class and subclasses, but not in clients

What are the advantages of data abstraction with the second condition? condition #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.

1) Provides a method of program organization 2) Aids modifiability (everything is associated with a data is together) 3) Separate compilation

Where can a polymorphic variable be defined?

defined in a class that is able to reference (or point to) objects of the class and objects of any of its descendants

abstract class (dynamic binding concepts)

includes at least one virtual method >> can't be instantiated

virtual

methods can be called through polymorphic variables and dynamic bound to messages ex: a pointer points to the method

What does inheritance allow for?

new classes defined in terms of existing ones >> by allowing them to inherit common parts


Conjuntos de estudio relacionados

Mastering Astronomy Chapter 15 - Galaxies - Tutorials Aid

View Set

Chapter 4: Premiums and Proceeds

View Set

CH 14 - Preoperative Nursing Management

View Set

Module #3: Collaboration and Teamwork

View Set

Section II - Life Insurance Practice Exam

View Set

Diet and Nutrition Module 2 Chapter 7 Energy Metabolism

View Set