Free web space - Chapter 8 Object-Based Programming 283 languages is that

Chapter 8 Object-Based Programming 283 languages is that client code often is dependent on implementation details of the data used in the code. This dependency might necessitate rewriting the client code if the data implementation changes. ADTs eliminate this problem by providing implementation-independent interfaces to their clients. The creator of a class can change the internal implementation of that class without affecting the clients of that class. Software Engineering Observation 8.2 It is important to write programs that are understandable and easy to maintain. Change is the rule, rather than the exception. Programmers should anticipate that their code will be modified. As we will see, classes facilitate program modifiability. The following example (an susequent examples) will require multiple class definitions in the same project. To add a class to a project, select Add Class from the Project menu. In the Add New Item dialog box that appears, enter the new class name in the Name text box and click the Open button. Note that the file name (ending with the .cs file extension) appears in the Solution Explorer below the project name. Our next example consists of classes Time1 (Fig. 8.1) and TimeTest1 (Fig. 8.2). Class Time1 contains the time of day in 24-hour clock format. Class TimeTest1 contains method Main, which creates an instance of class Time1 and demonstrates the features of that class. 1 // Fig. 8.1: Time1.cs 2 // Class Time1 maintains time in 24-hour format. 3 4 using System; 5 6 // Time1 class definition 7 public class Time1 : Object 8 { 9 private int hour; // 0-23 10 private int minute; // 0-59 11 private int second; // 0-59 12 13 // Time1 constructor initializes instance variables to 14 // zero to set default time to midnight 15 public Time1() 16 { 17 SetTime( 0, 0, 0 ); 18 } 19 20 // Set new time value in 24-hour format. Perform validity 21 // checks on the data. Set invalid values to zero. 22 public void SetTime( 23 int hourValue, int minuteValue, int secondValue ) 24 { 25 hour = ( hourValue >= 0 && hourValue < 24 ) ? 26 hourValue : 0; 27 minute = ( minuteValue >= 0 && minuteValue < 60 ) ? 28 minuteValue : 0; Fig. 8.1 Fig. 8.1Fig. 8.FiFi1g. 8.1g. 8.1Time1abstract data type represents the time in 24-hour format. (Part 1 of 2.)
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.

Leave a Reply