Concept
How can a Student object become more flexible?
"A more flexible approach might be to allow the construction of a Student instance without having to provide a course schedule. Instead, we could add a method that allowed the outside code to add a course to the student. For example,\n\n1 public function addCourse($c) {\n\n2 $this->schedule[] = $c;\n\n3 }\n\nThis adds some flexibility to our object, but removes the immutability property. Design is always a balance and compromise between competing considerations."
Related Ideas
- How can adding an addCourse method make a Student object more flexible?ComputerScienceOne · Example
- How should a class manage owned collections and avoid shallow copies?ComputerScienceOne · Composition
- How does composition allow objects to own instances of other objects?ComputerScienceOne · Composition
- Why are getters, setters, and immutable member variables useful?ComputerScienceOne · Constructors
- How does a constructor initialize a PHP object?ComputerScienceOne · Constructors
- How does composition model objects made up of other objects?ComputerScienceOne · Composition
- How do accessor and mutator methods use this to access instance variables?ComputerScienceOne · Accessor & Mutator Methods
- What is composition in object-oriented class design?ComputerScienceOne · Common Methods