1 / 9

Thinking in Objects

Thinking in Objects. Chapter 10. Immutable Objects and Classes. The String class is immutable. How to make our Circle class immutable? delete the set method! radius is private, cannot be changed without a set method. Scope of Variables. class variable vs . local variable

thy
Download Presentation

Thinking in Objects

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Thinking in Objects Chapter 10

  2. Immutable Objects and Classes • The String class is immutable. • How to make our Circle class immutable? • delete the set method! • radius is private, cannot be changed without a set method

  3. Scope of Variables • class variable vs. local variable • publicclass Foo { • privateintx = 0; //Class variable • privateinty = 0; • publicvoid p(){ • intx = 1; //Local variable • System.out.println("x = " + x); • System.out.println("y = " + y); • } • }

  4. The this Keyword • The this keyword is the name of a reference that refers to an object itself. • reference a class’s hidden data fields

  5. The this Keyword • enable a constructor to invoke another constructor of the same class

  6. Class Abstraction and Encapsulation • Class abstraction means to separate class implementation from the use of the class. • The detail of implementation is encapsulated and hidden from the user. • developer vs. user

  7. The Loan Class • UML (Unified Modeling Language) diagram

  8. The BMI (Body Mass Index) Class

  9. The BMI Class • BMI = weight (in kilograms) / height2 (in meters) • BMI Interpretation • below 16 seriously underweight • 16-18 underweight • 18-24 normal weight • 24-29 overweight • over 29 seriously overweight

More Related