02+-+Recursion - 5/4/2009 Abstraction Ve 280 Programming...

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

View Full Document Right Arrow Icon
5/4/2009 1 Procedural Abstraction and Recursio Ve 280 Programming and Introductory Data Structures Procedural Abstraction and Recursion Abstraction y Abstraction is a many-to-one mapping that reduces complexity and eliminates unnecessary details by providing only those details that matter. y 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. y There are two types of abstraction: y Procedural (the topic of the next three weeks) y Data Procedural Abstraction y Decomposing a program into functions is a way of providing “computational” abstractions. y Rather than simply being collections of commonly used code, functions provide a useful tool for implementing procedura functions provide a useful tool for implementing procedural abstraction within a program. Procedural Abstraction y For any function, there is a person who implements the function (the author) and a person who uses the function (the client). y 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. y 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! y In individual programming, you will often be the author and the client. Sometimes it is to your advantage to “forget the details” and only concentrate on higher levels of functionality. Procedural Abstraction y Procedural abstractions, done properly, have two important properties: y Local: the implementation of an abstraction can be understood without examining any other abstraction implementation. y 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. y These properties only apply to implementations of abstractions, not the abstractions themselves. y It is CRITICALLY IMPORTANT to get the abstractions right before you start writing a bunch of code. y If you change the abstraction that is offered, the change is not local, nor is the new version substitutable. Procedural Abstraction y Unfortunately, abstraction limits the scope of change. y If you need to change what a procedural abstraction does, it can involve many different changes in the program. y However, if a change can be limited to replacing the implementation of an abstraction with a substitutable implementation, then you are guaranteed that no other part of the project needs to change. This is vital for projects that involve many programmers.
Background image of page 1

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

View Full DocumentRight Arrow Icon
5/4/2009 2 Procedural Abstraction Function Definitions vs. Declarations y In small programs, often we just define functions before they are used. y
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

02+-+Recursion - 5/4/2009 Abstraction Ve 280 Programming...

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

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