福建农林大学计算机与信息学院JAVA语言程序设计课件Chapter10 Thinking in Objects.pptVIP

  • 7
  • 0
  • 约5.74千字
  • 约 23页
  • 2019-05-06 发布于广东
  • 举报

福建农林大学计算机与信息学院JAVA语言程序设计课件Chapter10 Thinking in Objects.ppt

Introduction to Java Programming Chapter 11 Introduction to Java Progrmming Chapter 10 Thinking in Objects Motivations You see the advantages of object-oriented programming from the preceding two chapters. This chapter will demonstrate how to solve problems using the object-oriented paradigm. Before studying these examples, we first introduce several language features for supporting these examples. Objectives To create immutable objects from immutable classes to protect the contents of objects (§10.2). To determine the scope of variables in the context of a class (§10.3). To use the keyword this to refer to the calling object itself (§10.4). To apply class abstraction to develop software (§10.5). To explore the differences between the procedural paradigm and object-oriented paradigm (§10.6). To develop classes for modeling composition relationships (§10.7). To design programs using the object-oriented paradigm (§§10.8-10.10). To design classes that follow the class-design guidelines (§10.11). 10.2 Immutable Objects and Classes If the contents of an object cannot be changed once the object is created, the object is called an immutable object and its class is called an immutable class. If you delete the set method in the Circle class in the preceding example, the class would be immutable because radius is private and cannot be changed without a set method. A class with all private data fields and without mutators is not necessarily immutable. For example, the following class Student has all private data fields and no mutators, but it is mutable. public class Student { private int id; private BirthDate birthDate; public Student(int ssn, int year, int month, int day) { id = ssn; birthDate = new BirthDate(year, month, day); } public int getId() { return id; } public BirthDate getBirthDate() { return birthDate; } } public class BirthDate { private int year; private int month; private int day; public BirthDate(int newYear,

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档