Introduction to Software Design EE 312 Software Design
























- Slides: 24
Introduction to Software Design EE 312 Software Design and Implementation I
Software Engineering n Goal ¨ Production of software that is effective and reliable, understandable, cost effective, adaptable, and reusable ¨ Because of the long lifetime many people will be involved Creation ¨ Debugging ¨ Maintenance ¨ Enhancement ¨ ¨ Two-thirds of the cost is typically beyond creation
Design Principles n Abstraction n Encapsulation n Modularity n Hierarchy
Principles n Abstraction n Encapsulation n Modularity n Hierarchy Determine the relevant properties and features while ignoring nonessential details
Principles n Abstraction n Encapsulation n Modularity n Hierarchy Separate components into external and internal aspects
Principles n Abstraction n Encapsulation n Modularity n Hierarchy Construct a system from components and packages
Principles n Abstraction n Encapsulation n Modularity n Hierarchy Ranking or ordering of objects
Abstract Data Types (ADT) n n n A specification of a set of data and the set of operations that can be performed on the data. Independent of concrete implementation Uses defined interface Hides details from the user (information hiding) Not the same as a data structure
ADT Example -- Stack n bool empty() ¨ Tests if this stack is empty. n E peek() ¨ Looks at the object at the top of this stack without removing it from the stack. n E pop() ¨ Removes the object at the top of this stack and returns that object as the value of this function. n push(E item) ¨ Pushes an item onto the top of this stack.
Why? n n n Allows implementation to be changed without violating ADT definitions Gives a standard list of structures to use and study Building blocks and tools Foundation for OOP Abstraction, Encapsulation, Modularity, Hierarchy
Object-Oriented Design n Purpose ¨ Promote thinking about software in a way that models the way we think and interact with the physical word n n Including specialization Object ¨ Properties or attributes ¨ Behaviors
Programming n Class ¨ Term for a type of software object n Object ¨ An instance of a class with ¨ specific properties and attributes
Programming Problem solving through the use of a computer system n Maxim n ¨ You cannot make a computer do something if you do not know how to do it yourself
Problem Solving Process Determine problem features Describe objects and methods Produce the classes and code Examine for correctness Analysis Design Implementation Testing Rethink as appropriate
Tips Find out as much as you can n Reuse what has been done before n Expect future reuse n Break complex problems into subproblems n Find out what is known about the problem Talk to the presenter Determine what attempts have succeeded and what attempts have failed
Preconditions and Postconditions Frequently a programmer must communicate precisely what a function accomplishes, without any indication of how the function does its work. Can you think of a situation where this would occur ?
What are Preconditions and Postconditions? One way to specify such requirements is with a pair of statements about the function. n The precondition statement indicates what must be true before the function is called. n The postcondition statement indicates what will be true when the function finishes its work. n
Example void write_sqrt( double x) // Precondition: x >= 0. // Postcondition: The square root of x has // been written to the standard output. . . .
Example Which of these function calls meet the precondition ? write_sqrt( -10 ); write_sqrt( 5. 6 );
Always make sure the precondition is valid. . . n The programmer who calls the function is responsible for ensuring that the precondition is valid when the function is called.
. . . so the postcondition becomes true at the function’s end. n The programmer who writes the function counts on the precondition being valid, and ensures that the postcondition becomes true at the function’s end.
On the other hand, careful programmers also follow these rules: When you write a function, you should make every effort to detect when a precondition has been violated. n If you detect that a precondition has been violated, then print an error message and halt the program. . . n. . . rather than causing a disaster. n
Example void write_sqrt( double x) // Precondition: x >= 0. // Postcondition: The square root of x has // been written to the standard output. { assert(x >= 0); . . .
Advantages of Using Preconditions and Postconditions Succinctly describes the behavior of a function. . . without cluttering up your thinking with details of how the function works. n At a later point, you may reimplement the function in a new way. . . n. . . but programs (which only depend on the precondition/postcondition) will still work with no changes. n
























