Concept
How can adding an addCourse method make a Student object more flexible?
"Alternatively, we could make our design a bit more flexible by allowing 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 schedule. Something like the following.\n\npublic void addCourse(Course c) {\n\nthis.schedule.add(c);\n\n}\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 a Student object become more flexible?ComputerScienceOne · Example
- How should a class manage owned collections and avoid shallow copies?ComputerScienceOne · Composition
- Why are getters, setters, and immutable member variables useful?ComputerScienceOne · Constructors
- What does the completed PHP Student class look like?ComputerScienceOne · Example
- What is composition in object-oriented class design?ComputerScienceOne · Common Methods
- How do accessor and mutator methods use this to access instance variables?ComputerScienceOne · Accessor & Mutator Methods
- How does composition model objects made up of other objects?ComputerScienceOne · Composition
- How does encapsulation group and protect related data?ComputerScienceOne · Encapsulation & Objects