How many Getters should it take to get an object?

Started by
14 comments, last by ChaosEngine 12 years, 11 months ago

Given that I know nothing about your code, I'm confused why you have Camera within Display. While logically a display is displayed with a camera I would think your object structure, if you are making them interdependent would be inverted. Cameras use displays to show their field of view Your binding of a camera to a display may also seems to negate the ability to have multiple monitor support. This is all just reading logically and trying to rationalize how your objects interrelate so take this with a grain of salt but you may definitely want to re-examine why you have those objects linked the way you do.

Well, as I said above, Display is a subsystem, rather than a display in the sense that you seem to interpret the name, which is understandable. It owns the Window object, the Renderer object, handles creation of the dialog boxes. It owned the camera object largely because I needed to put the camera somewhere. I've put the camera in the World class, as owl mentioned that he did, and it does simplify a lot of code. I had to do a bit of fudgery since the Menu is essentially another World object, and also needed the camera. But I just realized that I could probably have a static camera in the base class....

I considered including multiple monitor support, but I don't have multiple monitors ;) Also, I don't think this would work well split across multiple screens:
gallery_37843_205_82548.png
Advertisement
Eh, who gives a f? It's only two-level deep. I prefer keeping my architecture clean than worrying about two getters.

As long as it's not getApplication().getScreens().getCurrentScreen().getDisplay().getRenderer().getWorld().getCamera(), you are fine.

Eh, who gives a f? It's only two-level deep. I prefer keeping my architecture clean than worrying about two getters.

As long as it's not getApplication().getScreens().getCurrentScreen().getDisplay().getRenderer().getWorld().getCamera(), you are fine.

QFE
Always strive to be better than yourself.

Eh, who gives a f? It's only two-level deep. I prefer keeping my architecture clean than worrying about two getters.

I can respect that approach to a certain extent. Especially since it's code that likely no one will ever use but me. But it seemed that there should be a better way. I wasn't worriedd--hell, the code worked just fine. It just looked off to me, and I'm not the type to let something like that go when it's improvable.

And my architecture is cleaner for it ;)
your logic is undeniable


XD
[size="2"]I like the Walrus best.
Think about it from a testability point of view (you are writing tests, right?); if you have
void SomeClass::Update( float dt ) { Camera& camera = _app.GetDisplay().GetCamera(); // do stuff }

then to test this, you need to make sure you have an app object populated with a display populated with a camera.

whereas for
void SomeClass::Update( float dt, Camera& camera )
{
// do stuff
}


All you need is a Camera object, which can be passed into the method.
if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight

This topic is closed to new replies.

Advertisement