Your SlideShare is downloading. ×
Chapter 07
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Chapter 07

45
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
45
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

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 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 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
  • 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