210 likes | 296 Views
Carrano : Chapter 1. Software Engineering and Object-Oriented Design Topics: Solutions Modules Key Programming Issues Development Methods Object-Oriented Principles. What is a Good Solution?. A solution is good if: The total cost it incurs over all phases of its life cycle is minimal
E N D
Carrano: Chapter 1 Software Engineering and Object-Oriented Design • Topics: • Solutions • Modules • Key Programming Issues • Development Methods • Object-Oriented Principles
What is a Good Solution? • A solution is good if: • The total cost it incurs over all phases of its life cycle is minimal • The cost of a solution includes: • Computer resources that the program consumes • Difficulties encountered by users • Consequences of a program that does not behave correctly • Programs must be well structured and documented • Efficiency is one aspect of a solution’s cost
What is a Module? • A Module is a part of a program that accomplishes a task. • In procedural programming, Modules are made up of one or more functions. • Large Modules may contain Sub-Modules.
Structure of a Module • Modules have two primary components: an Interface and Internal Components. • In procedural programming, a module’s interface is just header of the function that you call to start the module. • Internal Components are the sub-modules/functions that do the task the module is designed to do.
How to Evaluate a Module • Cohesion • A highly cohesive module performs one well-defined task • Leads to modular solutions • Reduces Coupling • Coupling • Modules with low coupling are independent of one another • Modules shouldn’t affect other modules when changed. • Low coupling increases Cohesion.
Seven Key Issues in Programming • Modularity • Style • Modifiability • Ease of Use • Fail-safe programming • Debugging • Testing
1) Modularity • Modularity has a favorable impact on • Constructing programs • Debugging programs • Reading programs • Modifying programs • Eliminating redundant code • Reuse of code
2) Style Programming Style can enhance code with: • Use of private data members • Proper use of reference arguments • Proper use of functions • Avoidance of global variables in modules • Error handling • Readability • Documentation
3) Modifiability • Modifiability is easier through the use of • Named constants • The typedefstatement
4) Ease of Use • The easier a program is to use, the more impressed users will be with it. • In an interactive environment, the program should prompt the user for input in a clear manner • A program should always echo its input • The output should be well labeled and easy to read
5) Fail-Safe Programming • Fail-safe programs will perform reasonably no matter how anyone uses them • Test for invalid input data and program logic errors • Check invariants • Enforce preconditions • Check argument values
6) Debugging • Programmers must systematically check a program’s logic to find and correct errors • Tools to use while debugging: – Single-stepping – Watches – Breakpoints – cout statements – Dump functions
7) Testing • Levels • Unit testing: Test functions, then modules • Integration testing: Test interactions among modules • System testing: Test entire program • Acceptance testing: Show that system complies with requirements
Development Methods, Waterfall • One simple but somewhat outdated method is the Waterfall Method. • Though it can be used modularly, this design method requires each preceding stage to be complete before progressing to the next stage. In practice, this leads to inflexibility and a constant state of incompleteness.
Development Methods, Iterative • Newer methods are iterative. • Many short, fixed-length iterations • Each iteration builds on the previous iteration until a complete solution is achieved • Each iteration cycles through analysis, design, implementation, testing, and integration of a small portion of the problem domain • Early iterations create the core of the system; further iterations build on that core
Development Methods, Iterative • Features of Iterative methods: • The partial system at the end of each iteration should be functional and completely tested • Each iteration makes relatively few changes to the previous iteration • End users can provide feedback at the end of each iteration One specific iterative method is the Rational Unified Process (RUP)
Object-Oriented Programming • The most modern approach to designing modules is the Object-Oriented approach. • Instead of creating groups of functions, create classes. • Classes are combinations of data sets and methods (functions that operate on the data set) • Classes are combined and caused to interact to create solutions.
Principles of Object-Oriented Programming (OOP) • Object-oriented languages enable us to build classes that can be used to instantiate (create) objects • A class combines • Attributes (characteristics) of objects of a single type • Typically data • Called data members • Behaviors (operations) • Typically operate on the data • Called methods or member functions • An object is an instance of a class. Class: Objects:
Principles of Object-Oriented Programming • Three principles of object-oriented programming • Encapsulation • Objects combine data and operations • Hides inner details • Inheritance • Classes can inherit properties from other classes • Existing classes can be reused • Polymorphism • Objects can determine appropriate operations at execution time
Object-Oriented Analysis and Design • Object-Oriented Analysis (OOA) • Coming up with the classes that can be used to define the problem. • Emphasis on what a solution must do. • Object-Oriented Design (OOD) • Understanding how the classes can interact and what they can do alone or together.
Applying the UML to OOA/D • UML (Unified Modeling Language) is very often used in OOA/D to define classes and their interactions. A UML class definition: A UML interaction diagram: