csci 162 lecture 8 martin van bommel. large-scale programming up to now we have been writing...
Post on 18-Jan-2018
214 Views
Preview:
DESCRIPTION
TRANSCRIPT
CSci 162
Lecture 8
Martin van Bommel
Large-scale Programming• Up to now we have been writing relatively short
programs to solve simple problem• Want to now think about the management of
large-scale programs• Top-down design still works to modularize a large
project into individual pieces• Want pieces to be implemented by different
programmers
Procedural Abstraction• After breaking down problem into solvable chunks,
must think about chunks separately• Procedural abstraction
– separate concerns of what a function does from details of how it does it
• Permits use of function in design of problem solution before implementation is done
• Think - integer array functions
Data Abstraction• Data abstraction
– separate concerns of types of data objects and the associated operations from the details of how represented in memory and implemented
• Permits focus on the use of the data in solving larger problems
• Again think integer array and its operations
Information Hiding• Abstractions enable designer to make
implementation decisions in a more ad-hoc fashion - can postpone implementation
• Concealing details of implementation of data object and only enabling manipulation via defined operations allows changes to be made at lower level without affecting upper
• Protecting implementation details from user is called information hiding
Reusable Code• Reusable code - can be used by many different
applications• Encapsulation - packaging data object together
with its operators in a library• Use #include to access the library• Want to be able to provide these ourselves
Header Files• Header file - text file containing all information
about a library needed by the compiler and the user of the library
• Contents– comment summarizing library’s purpose– #define directives– type definitions for library– comments for each library function– function prototypes in form extern prototype
Implementation Files• Implementation file – C++ source file containing
code of library’s functions and any other information needed for compiling
• Contents– comment summarizing library’s purpose– #include directives for header file and others– #define directives needed in implementation– type definitions used only in implementation– function implementations (including comments)
Interface
• Conceptual entity• Boundary between the implementation of a library
and programs that use that library• Information passes across boundary whenever
functions in library are called• Interface mediates and gives structure to the
exchange of information between library and its users - .h file serves as interface
Example
• Math library - sqrt function• Implementation contains steps to calculate square
root of a number• User needs not know implementation, only use of
function – - how to pass in value and get back result
• Shown in <cmath> - file “cmath.h”– double sqrt(double);
Interface Terminology
• Implementor - defines functions– programmer who implements a library
• Client - uses functions– programmer who calls functions in library
• Both must know:– Function name– The arguments and their types– The type of the return result
Interface Design
• Unified - single abstraction with theme• Simple - hide all complexity from client• Sufficient - meet the needs of client• General - meet needs of different clients• Stable - never change structure and effect
of a function in interface, even ifimplementation changes or morefunctions added
top related