constructs Flashcards

1
Q

what is a procedure?

A
  • way of grouping code together to form an abstraction

* can be used again and again and bugs found only require fixing once

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

behavior of a procedure - 3

A
  • operates on its data (data is not abstract)
  • specified via its declaration (aka prototype/signature)
  • any data representations are usable throughout the program
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is a module?

A
  • collection of procedures and variables
  • allows procedures to share hidden data
  • provide a public (interface) and private (implementation) view
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Pascal supports

A
  • supports procedures and variables within procedures

* a collection of procedures cannot share hidden data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

C supports

A
  • 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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

type abstraction through modules - 3

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

limited type (modules) - 4

A
  • 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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

limited types in C

A

done through opaque pointer types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

opaque pointer types

A

a pointer to an incomplete type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

limitation of C’s type abstraction

A

objects created obey pointer semantics

  • need explicit initializer (constructor)
  • need explicit de-initialize (destructor)
  • assignment copies pointer, not the object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is a class? - 5

A
  • 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”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

classes vs. objects

A
  • objects are concrete; classes are abstract

* operations performed on objects only (not on classes)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what is an object?

A

an object is an instance of a class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what is a struct?

A

a class in which all members are public by default

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

classes in C++

A
  • generalization of structures
  • simply a struct in which all members are private by default
  • can contain data and functions (only data in C)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

interface vs. implementation locations (class)

A
  • interface should be in a header file
  • implementation should be in a separate source file
  • client only needs header file and compiled source file
17
Q

inlining

A
  • C++ allows function bodies (implementation) in header files so that the body of the function can be expanded at the point of its call
  • ideally the compiler does this for you (don’t put function bodies in header unless very short)
18
Q

what are member functions (C++) or methods (rest of OO world)?

A
• functions within a class in C++
• two special member functions
  1) constructors
  2) destructors
19
Q

what is a constructor?

A
  • named after the class, has no return type
  • job: initialize members of the class
  • implicitly called when an object is declared
20
Q

what is a destructor?

A
  • each class can have one
  • has the same name as the class preceded by a tilde
  • job: release resources allocated or in use by the object
  • always called implicitly
21
Q

what is a resource?

A

• anything the object has created, been allocated or has in use