Bifalgorithm post · Computer science one · Example

How can a Student object become more flexible?

How can a Student object become more flexible? (Computer science one · Example) — "A more flexible approach might be to allow the construction of a Student ins…

Ideas in this flowchart

  • Flexible Student construction trades immutability for flexibility.
  • A Student instance can be constructed without providing a course schedule.
  • This approach allows the schedule to be supplied after construction.
  • Outside code can add a course to the student.
  • The addCourse($c) method appends the course to the schedule.
  • The method implementation is: $this->schedule[] = $c;
  • The object gains greater flexibility.
  • The object no longer remains immutable.
  • Design balances competing considerations through compromise.
Feed/

How can a Student object become more flexible?

No cover

Channel

Computer science one

1 page

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

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.