Chapter 07

191 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
191
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Chapter 07

  1. 1. Object-Oriented Programming and Classes Chapter 7
  2. 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. 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. 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. 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. 6. 7 ProgramDesign 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. 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. 8. 7 Overloading Constructors Constructor methods are used when an object is instantiated. Overloaded constructors provide optional ways of creating objects.
  9. 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
  10. 10. 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

×