Skip to content

Latest commit

 

History

History
33 lines (21 loc) · 1.93 KB

ProgramArchitecture.md

File metadata and controls

33 lines (21 loc) · 1.93 KB

Program Architecture

Objects Should Not Draw Themselves

Generally objects shouldn't know how to draw themselves. Generally there should be dedicated objects or functions responsible for drawing other objects.

By making another object responsible for rendering, it is possible to choose different rendering strategies, thus producing more flexible code.

Concrete questions with concrete answers:

For a more abstract look at the problem:

One potential exception to this rule is in GUI programming where controls within the GUI might be responsible for drawing themselves, but this is an exception, not the rule, and it's not always true, it depends on the circumstances.

Inheriting to Avoid Code Duplication or to Inherit Functionality is Generally Bad

The point of inheritance is not to facilitate code reuse through inheriting a parent class's code. The intent of inheritance is to facilitate "subtype polymorphism" and consequently "Liskov substitution".

Inheritance does facilitate code reuse, but not directly via inheriting a parent class's code. It facilitates code reuse by allowing algorithms to be written for a particular interface (embodied by the parent class), so that child objects inheriting the parent can then be passed to the function implementing that algorithm.