02+-+Recursion - EECS 280 Programming and Introductory Data...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Procedural Abstraction and Recursion EECS 280 Programming and Introductory Data Structures
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Abstraction Abstraction is a many-to-one mapping that reduces complexity and eliminates unnecessary details by providing only those details that matter. For example, there are several ways to implement a multiplication algorithm (table lookup, summing, etc. .). Each looks quite different internally than the other, but they do the same thing. In general, a user won’t care how it’s done, just that it multiplies.
Background image of page 2
Procedural Abstraction Decomposing a program into functions is a way of providing “computational” abstractions. Rather than simply being collections of commonly used code, functions provide a useful tool for implementing procedural abstraction within a program.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Procedural Abstraction For any function, there is a person who implements the function (the author) and a person who uses the function (the client). The author needs to think carefully about what the function is supposed to do, as well as how the function is going to do it. In contrast, the client only needs to consider the what , not the how . Since how is much more complicated, this is a Big Win for the client!
Background image of page 4
Procedural Abstraction Procedural abstractions, done properly, have two important properties: Local: the implementation of an abstraction can be understood without examining any other abstraction implementation. Substitutable: you can replace one (correct) implementation of an abstraction with another (correct) one, and no callers of that abstraction will need to be modified. These properties only apply to implementations of abstractions, not the
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Procedural Abstraction Unfortunately, abstraction limits the scope of change. If you need to change what a procedural abstraction does, it can involve many different changes in the program. However, if a change can be limited to replacing the implementation of an abstraction with a substitutable implementation, then you are guaranteed
Background image of page 6
Procedural Abstraction Function Definitions vs. Declarations In small programs, often we just define functions before they are used. In larger programs, it is useful to separate the declaration of a function from its definition. A declaration provides the “type signature” of a function, also called the function header. Function headers can be placed in their own file and accessed using the
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Function Details All C++ functions take zero or more arguments and return a result of some type. There is a special type, called “void”, that means “no result is returned”. void is still a type, even though it is “the type with no legal values”. Typically, a function's signature defines all
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 49

02+-+Recursion - EECS 280 Programming and Introductory Data...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online