Presentation is loading. Please wait.

Presentation is loading. Please wait.

Object-Oriented Programming and Classes Chapter 7.

Similar presentations


Presentation on theme: "Object-Oriented Programming and Classes Chapter 7."— Presentation transcript:

1 Object-Oriented Programming and Classes Chapter 7

2 7 Refactoring Classes should perform one task. If a class performs multiple tasks, it should be refactored into two or more classes. This process is analogous to factoring composite numbers into their primes.

3 7 Setting State An object uses member variables to keep track of its own state. The Ball object knows its own: x and y location x and y velocity

4 7 Implementing Methods The Ball class is responsible for: Moving itself Drawing itself The World does the following: Erases the ball Moves the ball Checks for ball collision and changes the ball velocity, if necessary Draws the ball

5 7 Encapsulating Responsibility A class should be responsible for its own behavior. Encapsulation makes programs easier to maintain and expand. It is easier to reuse encapsulated classes in other programs.

6 7 Program Design Considerations Good software design requires planning, evaluation, and conscious implementation decisions. Symptoms of poor program design: Many small, data-only objects and one large, controlling object that makes everything happen Objects that need to know a lot of details about another object’s implementation

7 7 Method Overloading Creating more than one version of a method with different parameter lists Compiler decides which method to use based on method signature. Number of parameters Order of parameters Type of parameters Overloading provides “optional” arguments.

8 7 Overloading Constructors Constructor methods are used when an object is instantiated. Overloaded constructors provide optional ways of creating objects.

9 7 Putting It All Together Ball class overloaded to permit clients to create different size Ball objects HWall class overloaded to allow clients to specify elasticity


Download ppt "Object-Oriented Programming and Classes Chapter 7."

Similar presentations


Ads by Google