1/23
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Abstraction
is a view or representation of an entity that includes only the most significant attributes
abstract data type
it is a user-defined data type that satisfies two conditions
adt first condition
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
adt second condition
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
adt first condition advantages
reliability—by hiding the data representations, user code cannot directly access objects of the type or depend on the representation, allowing the representation to be changes without affecting user code
reduces the range of code and variables of which the programmer must be aware
name conflicts are less likely
adt second condition advantages
provides a method of program organization
aids modifiability (everything associated with a data structure is together)
separate compilation
adt language requirements
a syntactic unit in which to encapsulate the type definition
a method of making type names and subprogram headers visible to clients, while hiding actual definitions
some primitive operations must be built into the language processor
adt design issues
can abstract data be parameterized?
what access controls are provided?
is the specification of the type physically separate from its implementation?
adt C++
based on C struct
a class is a type
the class is the encapsulation device
each instance of a class has its own copy of the class data members
instances can be static, stack dynamic, or heap dynamic
C++ information hiding
Private
clause for hidden entities
Public
clause for interface entities
Protected
clause for inheritance
C++ constructors
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-dynamic
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
C++ destructors
functions to cleanup after an instance or destroyed; usually just to reclaim heap storage
implicitly called when the object’s lifetime ends
can be explicitly called
name is the class name, preceded by a tilde (~)
Friend Functions or classes
to provide access to private members to some unrelated units or functions
adt Java
all user-defined types are classes
all objects are allocated from the heap and accessed through reference variables
individual entities in classes have access control modifiers (private or public), rather than clauses
implicit garbage collection of all objects
it has second scoping mechanism, package scope, which can be used in place of friends
adt c#
based on C++ and Java
adds two access modifiers, internal and protected internal
all class instances are heap dynamic
default constructors are available for all classes
garbage collection is used for most heap objects, so destructors are rarely used
structs are lightweight classes that do not support inheritance
parameterized adt
it allows designing an ADT that can store any type elements - only an issue for static typed languages
also known as generic classes
java parameterized adt
most common generic types are the collection types, such as LinkedList and ArrayList
large program needs
some means of organization, other than simply division into subprograms
some means of partial compilation (compilation units that are smaller than the whole program)
encapsulation
solves the large program needs
it is a grouping of subprograms that are logically related into a unit that can be separately compiled (compilation units)
nested subprograms
organizing programs by nesting subprogram definitions inside the logically larger subprograms that use them
C encapsulation
files containing one or more subprograms can be independently compiled
the interface is placed in a header file
#include
preprocessor specification—used to include header files in applications
C encapsulation problems
the linker does not check types between a header and associated implementation
the inherent problem with pointers
C++ Encapsulation
can define header and code files, similar to those of C
Or, class 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 grant access to private members of a class
naming encapsulations
large programs define many global names; need a way to divide into logical groupings
this is used to create a new scope for names