CS102 - Java Programming Language Lecture Notes

Object-Oriented Design

Software Development Activities

  • Involves four key activities:

    • Establishing requirements

    • Creating design

    • Implementing code

    • Testing implementation

  • Activities overlap and interact rather than follow a strict linear process.

Requirements

  • Specify tasks for the program (what it should do, not how).

  • Initial requirements often need critiquing and elaboration.

  • Carefully defined requirements reduce time and cost of projects.

Design

  • Specifies how requirements will be accomplished and broken into manageable pieces.

  • Object-oriented design focuses on the necessary classes and their interactions.

  • Low-level design includes details on how individual methods function.

Implementation

  • Translating designs into source code.

  • Important decisions occur during requirements and design phases, not during coding.

  • Focus during implementation on coding details, style guidelines, and documentation.

Testing

  • Ensures the program addresses all specification constraints.

  • Involves finding and fixing errors through debugging.

Identifying Classes and Objects

  • Crucial to object-oriented design; identify classes based on requirements.

  • Classes represent a group of objects (e.g., Coin, Student), and methods (verbs) define class behaviors.

  • Not every noun from requirements corresponds to a class.

Class Characteristics

  • Determine responsibilities and detail level of each class cautiously.

  • Aim for efficient class design; use general classes (like Appliance) when applicable.

Static Class Members

  • Static methods can be called via class names; critical in design decisions.

  • Static variables create a single shared instance across all class objects.

  • Static methods cannot reference instance variables but can reference static/local variables.

Example Usage of Static Members

  • Static methods store information, like counting instances of objects (e.g., tracking Slogan object creations).

Summary of Key Concepts

  • The static modifier links methods/variables to the class rather than instances.

  • Static members are necessary for shared data among instances.

  • Understanding the relationship between instance and static variables/methods is crucial in design.