Bifalgorithm post · Computer science one · Example

How can adding an addCourse method make a Student object more flexible?

How can adding an addCourse method make a Student object more flexible? (Computer science one · Example) — "Alternatively, we could make our design a bit more…

Ideas in this flowchart

  • Flexible object design can trade immutability for easier construction and modification.
  • A Student instance can be constructed without providing a course schedule.
  • Outside code can add a course to the schedule later.
  • The addCourse(Course c) method performs this addition.
  • Its implementation calls this.schedule.add(c).
  • This alternative adds flexibility to the object.
  • This alternative removes the object's immutability.
  • Design is a balance and compromise between competing considerations.
Feed/

How can adding an addCourse method make a Student object more flexible?

No cover

Channel

Computer science one

1 page

"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."

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.