Cartesian Plane Lesson 7: Property Management

In this lesson, we will develop and test the PropertyManager class. This class will be responsible for managing all properties declared in the CPConstants class, as they are now and as they may be modified in the future. The management tasks include:

  • Establishing initial values for the properties. A default value for each property is declared in CPConstants, but the default value can be overridden from a variety of sources, such as the command line or an initialization file.
  • Providing access to these properties. It allows the programmer to get or set the value of any property, or even define new properties.
  • Notifying facilities when the value of a property changes. For example, if the user changes the axes color, the CartesianPlane class must be notified so it can redraw the plane in the updated color.

Page 1 of this lesson focuses on establishing the PropertyManager class, with an emphasis on the algorithm and methods for locating initial values. Page 1 introduces the following topics:

  • What is a property?
  • How may a property value be set on the command line?
  • What is the environment, and how may it be used to set a property value?
  • What is an initialization file? How do we read and process one?
  • What is a resource file? How do we incorporate resources into a project?
  • What is an event? How can we use event handling to report changes in property values to interested clients?

Page 2 completes the development of the PropertyManagement class. It provides an introduction to reflection and uses it to automatically find properties in CPConstants.

Page 3 provides an introduction to Java’s process management framework, which we will use for testing the Property Manager. It discusses how to create and communicate with a child process.

Page 4 presents a JUnit test to validate the PropertyManager’s initialization logic. The tests in this class start a child process with a predetermined environment and command line. It automatically generates initialization files with predictable property value declarations and makes them available to the child process. It then interrogates the child process’s PropertyManager, verifying that each of its properties has been initialized from the correct source.

Page 5 introduces a second JUnit test class that validates parts of the PropertyManager not tested by the JUnit test on the previous page.

GitHub repository: Cartesian Plane Part 7a

Previous lesson: Cartesian Plane Lesson 6: Unit Testing, Page 2

Next: Property Management, Page 1