constructs Flashcards
what is a procedure?
- way of grouping code together to form an abstraction
* can be used again and again and bugs found only require fixing once
behavior of a procedure - 3
- operates on its data (data is not abstract)
- specified via its declaration (aka prototype/signature)
- any data representations are usable throughout the program
what is a module?
- collection of procedures and variables
- allows procedures to share hidden data
- provide a public (interface) and private (implementation) view
Pascal supports
- supports procedures and variables within procedures
* a collection of procedures cannot share hidden data
C supports
- limited support for modules (mimics modules with keyword “static” inside a file)
- uses name equivalence for structs (actual structure definition is placed in the same file…aka module)
type abstraction through modules - 3
- done through limited or opaque types
- representation of a type is kept hidden
- most implementations of true modules provide type as well as procedural abstractions
limited type (modules) - 4
- implementation visible only to module
- name of type visible to client
- name equivalence must be used (not structural)
- usually done as pointer types (size of a pointer is generally the same regardless of object being pointed to)
limited types in C
done through opaque pointer types
opaque pointer types
a pointer to an incomplete type
limitation of C’s type abstraction
objects created obey pointer semantics
- need explicit initializer (constructor)
- need explicit de-initialize (destructor)
- assignment copies pointer, not the object
what is a class? - 5
- corresponds to a type
- same abilities as built-in types
- should be first class
- supports information hiding (public and private components)
- abbr. for “class of objects”
classes vs. objects
- objects are concrete; classes are abstract
* operations performed on objects only (not on classes)
what is an object?
an object is an instance of a class
what is a struct?
a class in which all members are public by default
classes in C++
- generalization of structures
- simply a struct in which all members are private by default
- can contain data and functions (only data in C)