CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ | Grades

Classes

Objects and Classes
Introduction
Encapsulation

How encapsulation works

  • The fields of a class store the data of a class.
  • The methods of a class define the tasks that a class can perform. Often, these methods provide a way to work with the fields of a class.
  • Encapsulation is one of the fundamental concepts of object-oriented programming. This means that the class controls which of its fields and methods can be accessed by other classes.
  • With encapsulation, the fields in a class can be hidden from other classes, and the methods in a class can be modified or improved without changing the way that other classes use them.

UML diagramming notes

  • UML (Unified Modeling Language) is the industry standard used to describe the classes and objects of an object-oriented application.
  • The minus sign (-) in a UML class diagram marks the fields and methods that can't be accessed by other classes, while the plus sign (+) signifies that access is allowed.
  • For each field, the name is given, followed by a colon, followed by the data type.
  • For each method, the name is given, followed by a set of parentheses, followed by a colon and the data type of the value that's going to be returned.
  • If a method doesn't require any parameters, the parentheses are left empty. Otherwise, the data type of each parameter is listed in them.
Previous | OOP Programming Concepts | Use | Encapsulation | Relationship between a class and its object | Next