1 / 28

Overview of Lecture

Overview of Lecture. Review of last lecture Software Design Overview Software Design Phases Example: Calendar Class Example: Date Class Implementing the Calendar Class Lab Error Handling C++ Exceptions Object Composition TimeCard Class Operator Overloading Operating Function

molivares
Download Presentation

Overview of Lecture

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Overview of Lecture • Review of last lecture • Software Design Overview • Software Design Phases • Example: Calendar Class • Example: Date Class • Implementing the Calendar Class • Lab • Error Handling • C++ Exceptions • Object Composition • TimeCard Class • Operator Overloading • Operating Function • Time24 Class • Member Function Overloading

  2. Review of Last Lecture • Information Hiding: • Each program component hides as much info as possible from the component users • In C++ this is done by placing components in the _____ part of the class • Abstract Data Types (ADT): • a collection of values and operations that act on those values encapsulated • In encapsulation, the users: • Do not need to know the hidden information • Are not allowed to directly manipulate or use the hidden information • Terms in relation to classes and ADT • Data members/ instance variables • Hold state of the object, each instance has its own copy • Member functions/ methods • Actions of the objects • Private sections • Accessible only by class • Public sections • Accessible by users • Time24 Class example

  3. Introduction to Object Design Techniques • There are a number of phases in in the software life cycle • It is important to design the public interface of a class and to develop algorithms for implementing class member functions carefully before beginning a class implementation • Testing and program maintenance is as important as creation of the original product because failure of running or updating the application results in the product becoming obsolete and a commercial failure • Error handling – the calling code should handle the error, not the member or free function that encounters the error • Exceptions are the better mechanism for handling errors • Object composition is a fundamental object design technique and it facilitates software reuse • Constructor initialization list can be used in providing initial values for objects included in by composition • Operator overloading is an object design technique that makes using a class easier and more flexible

  4. Software Design • A computer program begins with a problem that the client wants solved • The process of building the program starts with an analysis of the problem • It proceeds through a series of stages to produce a product that is reliable and easy to maintain • Prior to the standardization of the software development life cycle: • Programmers added code to software with little attention to its integration into the system • Over time systems deteriorated and became so difficult to update that programmers had to develop new software to replace them

  5. Software Design Techniques • The software life cycle consists of: • Request phase • Analysis phase • Design phase • Implementation phase • Testing phase • Maintenance phase (RADIT M) • Each has an equal importance in the Software Development Lifecycle

  6. Software Design Phases • Request: • Client perceives a need for a software system to solve a problem or to facilitate more effective operations • Client meets with a computer consultant who undertakes a feasibility study for the project

  7. Software Design Phases • Analysis: • In this phase, the system requirements are determined • Systems analyst determines requirements and is the intermediary between the client and the software engineers Result: a functional specification of the software system that includes a list of needs and special requirements.

  8. Software Design Phases • Design: • Translate the functional specification into an abstract model of the system. • Identify the components of the system and develop algorithms that will be used for implementation • Create the declaration of the classes including their attributes and public member functions Describe how the classes are related to each other Design the algorithms that allow the classes to effectively interact

  9. Software Design Phases • Implementation: • Use a programming language and the design specification to code the different components of the system • Convert the design into a program • Implement the classes independently and verify the action of their member functions • Implement program units that coordinate object interaction • Code the main program that manages the overall execution of the software system • Often, the implementationstage will discover errors or oversights in design

  10. Software Design Phases • Testing: • Check the program for logical and runtime errors and verify that the system meets the specifications of the client • Analysis, design, and implementation phases interact to bring about modifications and corrections to the specifications, and the code’s effective interaction among the phases depends on frequent and systematic testing • Test the classes and functions which are the individual units of the software system • Perform integrative testing to ensure that the units fit together to create a program that runs correctly and efficiently

  11. Software Design Phases • Maintenance: • Periodically update of the software to stay current and to respond to changing needs of the client • Begins as soon as the client installs the system • The client will identify bugs or features that must be changed or added • A client may add new hardware and/or find new applications for the software • Modern software systems must be regularly upgraded or they will eventually become obsolete and unusable.

  12. Example: CLASS Calendar August 1981 1. Request: • Computer professionals have a preliminary session with the client who has requested this meeting • The client asks for a simple software which will facilitate that upon entering month and year, the program will display a calendar e.g. entering 8 and 1981 will result in a calendar with the month August, 1981 being displayed • The client is of the opinion that for their particular chemical manufacturing plant, a system that can easily call up a particular month of a particular year will help in the effectiveness of running their business

  13. CLASS Calendar 2. Analysis • Involves understanding what the client’s business involves and how this program will be beneficial for them so that it can be designed and built for that purpose – the objective has to be clear and the client and programmer have to be on the same page • In this case, the client has a chemical manufacturing plant which needs to keep track of certain chemical compounds. Each chemical pack has a tracking number which includes sell date by month number and the year. • A feasibility study has to be carried out to see whether building the software will be cost and time effective for the client (this is paramount in the case of more complicated software design and global companies) • The system requirements should also be assessed • This is carried out by a system analyst who acts as a intermediary between the client and the software engineer Results of the Analysis Phase: Functional Specification of the software system that includes: • input: the program prompts the user to enter a month (1 to 12) and a year (1900 or later) • output: displays a calendar with the name of the month, and the year in a label, dates listed as Sun, Mon, Tue,…, Sat, and the dates listed in a table below • details of assumptions: use as base reference that Jan 1, 1900 is Mon • processing requirements: client wants flexibility to take program and produce a yearlong calendar by calling the monthly calendar display for each calendar

  14. 3. Design of Program The problem is viewed as a set of objects that interact to carry out tasks The software system represents each object by a class consisting of data and of operations that manage that data Object-oriented programming employs a bottom-up approach that first identifies the objects and their operations and then builds scenarios that describe how the objects should interact In this phase the structural blueprint are designed for programmers to use to implement the individual components and relate in the overall system CLASS Calendar Object 1 Class Data Operations Object 2 Class Data Operations Object 3 Class Data Operations Main Program Object 4 Class Data Operations Object 5 Class Data Operations Object n Class Data Operations Overall System

  15. class calendar { public: calendar(int m = 1, int y = 1900); // initialize the month and year for display. // precondition: month is in the range 1 to 12 and year // is 1900 or later CLASS calendar Declaration “d_cal.h” Designing the Calendar Class Design begins by viewing a calendar month as an object Create a calendar class whose public-member functions meet the specifications given by the client The class data will store the month and year A user will input the month and year, so the constructor uses these values to initialize the data

  16. void displayCalendar() const; // display the calendar with a header and a table of dates int getMonth() const; // return the current month for the calendar int getYear() const; // return the current year for the calendar CLASS calendar Declaration “d_cal.h” Designing the Calendar Class The operation displayCalendar() outputs the calendar The client wants the flexibility to output a yearly calendar by displaying the individual calendars for each month in the year – to provide this capability, we add the functions getMonth() and getYear() to access the data and the functions setMonth() and setYear() to update the data The constructor and the set functions have preconditions that ensure the month and the year are within their correct ranges

  17. void setMonth(int m); // update the month for the calendar // precondition: m must be in the range 1 to 12 void setYear(int y); // update the year for the calendar // precondition: y must be >= 1900 private: . . . ; CLASS calendar Declaration “d_cal.h” Designing the Calendar Class

  18. Designing the displayCalendar() Algorithm • The member function displayCalendar() outputs both the calendar label and the grid of dates and names for the days in the week – these are distinct tasks • To display the label , we need to convert the integer value for the month to a string that gives the name of the month • Displaying the dates under the correct names for the days in the week requires knowing the day corresponding to the first date of the month, the number of days in the month etc. • To isolate the tasks, our implementation design creates 2 private-member functions in a class implementation (see pg 62) • The key element in the design of the calendar problem is the algorithm for displayDates()

  19. displayCalendar() • Once displayCalendar() begins placing dates in the calendar grid, it must know when to stop • We must have access to the number of days in the month, including special attention to February in case of a leap year • Finding the Day for the First of the Month • Allocate values to days of the week (Sun is 0, Mon is 1…Sat is 6) • Jan 1, 1900 is Mon (not a leap year) – what is Jan 1, 1901? • (365 + 1)/7 = 52 r 2  Tues • Jan 1, 1999 is Friday – what is April 1, 1999 (not a leap year) • Jan (31) +Feb (28) + Mar (31) = 90 days (90 + 5)/7 = 13 r 4  Thurs

  20. CLASS date “d_date.h” Constructor date(int mm = 1, int dd = 1, int yy = 1900); Initializes the date with default January 1, 1900 Class date

  21. CLASS date “d_date.h” Operations int daysInMonth(); Returns the number of days for the month. If the year is a leap year, month 2 (February) returns 29 int getMonth(); Returns the month for the current date int getYear(); Returns the year for the current date bool isLeapYear(); Return true if the year is a leap year, otherwise returns false int numberOfDays(); Return the number of days into the year void setMonth(int mm); Update the month in the current date void setYear(int yy); Update the year in the current date Class date

  22. Program Implementation 4. Implementing the Program • The implementation phase of the software development cycle uses the syntax and features of a programming language like C++ to convert the design into a program • A design includes a series of classes and functions to direct the interaction among the objects: • Steps • Implement the classes independently and verify the actions of their member functions • Implement program units that coordinate object interaction • Code the main program that manages the overall execution of the software system • Theoretically, in the development cycle, implementation should ideally follow the design • In reality there is dynamic interaction between design and implementation since many errors and deficiencies in design are understood only during the implementation phase of a program • To correct the errors and deficiencies, it is necessary to modify and update the initial design

  23. Testing and Debugging Program 5. Testing the Program • Analysis, design, and implementation are interactive processes that bring about modifications ad corrections to the specifications and the code • Effective interaction among the phases depends on frequent and systematic testing • It is necessary to test the classes and functions that are the individual units of the software system as well as to perform integrative testing to ensure that the units fit together to create a program that runs correctly and cohesively and efficiently and meets the specifications of the client Program Validation Testing: involves the client and the software developers to ensure that the correct problems are being solved. This is carried out throughout the development cycle

  24. Correctness of a Program • There a number of testing strategies that enable developers to verify the correctness of a program • These strategies fall into 2 categories: • Blackbox tests: focus on the input and output behavior of the program without concern for the internal structure of its classes and functions. A programmer performs blackbox testing by choosing input data for which the output is known • Whitebox tests: focus on the internal structure of the program. The test requires data that will exercise each line of code in each function. Special attention is paid to statements and loops within the code

  25. Maintaining the Program 6. Maintaining the Program • Ideally, the analysis, design, and implementation phases of the software-development cycle produces an error-free application that meets all of the client’s needs • But let’s keep it real! This rarely happens! • So in order to ensure the longevity and effectiveness of the software, the maintenance phase must begin as soon as the client installs the system • Under the scrutiny of usage of the client, bugs or features that need to be modified are identified • Over time, a client adds new hardware and finds new applications for the software • Software systems must be regularly upgraded

  26. Handling Runtime Errors • Handling errors during function execution is an important aspect of program design • When implementing any function, a programmer must be aware that the code will execute in a runtime environment that includes not only the computer system but also a user. • There are three fundamental ways to handle errors: • Output an error message and terminate the program • Generally avoided unless necessary • Return a Boolean flag from the function call indicating that an error occurred • Grants the advantage of leaving the decision about how to handle the error to the calling code block • use the C++ exception mechanism • The best approach

  27. C++ Exception Mechanism • C++ exceptions are handled by three keywords: • Try Function calls and code that may generate an exception are placed in a try block • Catch The exception handler outputs an error message and either takes corrective action or terminates the program • Throw Bypasses the normal function return mechanism and searches chain of previous function calls until it locates a catch block.

  28. C++ Exception Mechanism • An exception is an object that contains information that is transmitted without using the normal function return process

More Related