Page 233 - Introduction to Programming with Java: A Problem Solving Approach
P. 233

                6.3 First OOP Class 199
  Specifications for a computer
     computer objects
                               erly. We want to keep you away from that trap until after you have developed good OOP habits. Therefore, we focus on instance variables and instance methods throughout this chapter and the next several chapters.
Apago PDF Enhancer
A class’s instance variables specify the type of data that an object can store. For example, if you have a class for computer objects, and the Computer class contains a hardDiskSize instance variable, then each computer object stores a value for the size of the computer’s hard disk. A class’s instance methods specify the behavior that an object can exhibit. For example, if you have a class for computer objects, and the Computer class contains a printSpecifications instance method, then each computer object can print a specifi- cations report (the specifications report shows the computer’s hard disk size, CPU speed, cost, etc.).
Note the use of the term “instance” in “instance variable” and “instance method.” That reinforces the fact that instance variables and instance methods are associated with a particular object instance. For ex- ample, each employee object would have its own value for a salary instance variable, which would be accessed through its adjustSalary instance method. That contrasts with class methods. Class methods are associated with an entire class. For example, the Math class contains the round class method, which is not associated with a particular instance of the Math class.
6.3 First OOP Class
In the next several sections, we put what you’ve learned into practice by implementing a complete OOP program. The program will contain a Mouse class, and it will simulate the growth of two Mouse objects
(we’re talking about rodents here, not computer pointing devices). As is customary with OOP
programs, we start the implementation process by describing the solution pictorially with specify OOP. a UML class diagram. A UML class diagram is a diagrammatic technique for describing
classes, objects, and the relationships between them. It is widely accepted in the software industry as a stan- dard for modeling OOP designs. After describing our mouse-simulation solution with a UML class diagram, we will present the Mouse program’s source code and walk you through it.
Figure 6.2 Conveyor belt portrayal of the class- objects relationship
      Use UML to
             




















































































   231   232   233   234   235