Archived

This topic is now archived and is closed to further replies.

LuckyNewbie

Am I the only one that groups similar functions into a class (and thinks it's ghetto)

Recommended Posts

Well, an example: I have an input class, so i make a class called "CInput" and add all the useful functions and variables... pointers to the input devices, Init() and Update(), etc..., but I only make one instance of the class, ever. Does this count as an abuse of classes and necessitating my quick extermination from humanity by the UN''s gene-cleanup squad? Is there a better way to do this? Sure, I could do an entirely static class that never has an instance, but I''m still pretty much in the same boat. Any thoughts? Confronted this problem before and didn''t think much about it? Found a better way? Halp. "Let me just ejaculate some ideas"

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
UN-gene-cleanup squad... pretty funny.

I wouldn''t say this is a freakish way of doing things. It sounds like you''ve made a singleton class, which is a strategy employed by many people. The difference is that, well, from what I get from your post, you define this class, and then you declare an instance of it. A singleton is along the same lines, only you don''t really declare an instace of it in the same way. You have a static function that returns a pointer to a single instance of the class. When set up correctly, you never have more than one instance of the class, which would make sense... you don''t really want more than one input class I would assume. Anyway, this singleton idea can be used to make a sound handler, mouse handler. The sky is the limit. En bref, not a freakish thing, and I don''t know if any of this post made any sense or helps you.

Share this post


Link to post
Share on other sites
I do the same thing, although I always try and write my code so that I could reuse it (but I never do) Sometimes if I realize I''m only going to use the code once, I try and think of a way to derive it from a current class, if applicable.

Share this post


Link to post
Share on other sites
quote:
Original post by LuckyNewbie
I have an input class, so i make a class called "CInput" and add all the useful functions and variables... pointers to the input devices, Init() and Update(), etc..., but I only make one instance of the class, ever. Does this count as an abuse of classes and necessitating my quick extermination from humanity by the UN's gene-cleanup squad?

Going purely on your description, it sounds perfectly reasonable.
quote:

Is there a better way to do this? Sure, I could do an entirely static class that never has an instance, but I'm still pretty much in the same boat.

Judging from the name of your class, and your description, presumably it is possible that you might write a program which has multiple input sources, in which case a static class will prevent you from representing each of those sources with an object.
quote:
Original post by ToohrVyk
I think you might want to look into singletons (ie classes that are meant to exist in only one version)

Singletons are the most widely known and therfore most abused of the `Design Patterns', and they are almost always the wrong answer to any question. In the OP's case, only ever needing to instantiate a single CInput is nowhere near strong enough a requirement to want to force only one CInput ever to exist.


[edited by - SabreMan on October 7, 2003 1:10:01 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Peon
I do the same thing, although I always try and write my code so that I could reuse it (but I never do)

`Reusable'' is a buzzword, so people think their code is somehow superior if they can convince themselves of its `reusability''. However, until you know that you have a situation where you can take a s/w module and use it in a new context, you don''t know what other contexts there might be. Guessing at other contexts is likely to be a waste of time.

It ain''t reusable until its been reused.

Share this post


Link to post
Share on other sites
When doing a demo a while ago I found it very useful to have a singleton input system class which trapped input and translated it into game commands. The level at which I captured input, however, was somewhat more coarse-grained than has been discussed; it was more of an input controller (that is, a class which knows how to control & route input) than an actual input device. This may be more along the lines of what you need than a singleton for the actual input device itself.

ld

Share this post


Link to post
Share on other sites