I currently have an object that is composed from several simple objects. Each simple object is used to render a particular portion of the larger object as a whole. Think of it as building a 3D structure such as a house for rendering to the screen:
- House
- Walls
- Roof
- Windows
- Doors
Now, in most cases, we can just render a model and the work is done, but in this case I am essentially building the model from scratch. Each piece can be built using more simplistic objects already present such as Mesh
. This however requires constructing the vertices and indices of each fundamental piece of the house.
The way the current code is set up I currently build each part of the house within the House
class which prevents reusability (which isn't really too big of a concern here), and definitely makes the House
class very hard to understand and maintain without spending half the day analyzing it. As a basic example:
public class House : RenderObject {
private Mesh[] walls;
private Mesh[] roof;
private Mesh[] windows;
private Mesh[] doors;
public void Initialize() {
// Build walls.
// Build roof.
// Build windows.
// Build doors.
}
}
My first thought is that the initialize method can be refactored into separate methods to handle building each piece; but, this conflicts with the thought that occurs simultaneously.
Should each piece of the House
object be its own class?
- This would improve:
- Maintainability
- Readability
- Reusability
My concern is that perhaps moving each piece to its own class
wouldn't really be worth the effort if it is never really reused, but then I begin arguing with myself along the lines of perhaps it could be, this is a public API after all.