#1
|
|||
|
OOP and "Manager" Classes for Common Code🤔
If I am writing a piece of software and it is going to have many instances of a few different types of objects is it better to aggregate common/repetitive code for updates into a "manager" type class than having all that code replicated across hundreds or thousands of objects?
For example, if I have an object, say, a Collider and it contains a collision box and maybe a method for correcting position on collision, is it better to implement the code for detecting collisions within that object or within a separate CollisionManager class that could iterate over all active colliders to check for collisions? I wouldn't think it would make a difference either way for speed, but it seems liek it would use a lot less memory to house all the collision code in a single instance than duplicating it across many objects.
__________________
<Millenial Snowfkake Utopia>
| ||
|
#2
|
|||||
|
Quote:
Even so, this sounds wrong: Quote:
But again, not a C guy, so maybe it works differently? I'd just be surprised if it did. If my understanding is correct, this is really more a code organization/architectural issue than a memory optimization one, and you should choose whichever approach best fits your application.
__________________
Loramin Frostseer, Oracle of the Tribunal <Anonymous> and Fan of the "Where To Go For XP/For Treasure?" Guides Anyone can improve the wiki! If you are new to the Blue server, you can improve the wiki to earn a "welcome package" of up to 2k+ platinum! Message me for details. | ||||
Last edited by loramin; 11-27-2018 at 12:35 PM..
|
|
#3
|
||||
|
Quote:
__________________
<Millenial Snowfkake Utopia>
| |||
|
#4
|
|||
|
oo yeah, found a diagram on stackexchange that depicts the same thing you said, Lor ^^;
Glad memory isn't really an issue, but still curious about best implementation though. Going to give it some more thought.
__________________
<Millenial Snowfkake Utopia>
| ||
|
#5
|
|||
|
0010101110101001010101000101001011
lol | ||
|
#6
|
||||
|
Quote:
Basically the book is a giant collection of "refactorings", ie. ways to take code written one way and re-write it in a better way without altering what it actually does. It also contains a chapter on "code smells", ie. patterns/signs that some code likely should be refactored. But most importantly, it doesn't just tell you what smells and refactorings to use: it tells you why, in a very well-thought out and logical fashion. When you start to learn how to identify "smelly" code patterns, how to improve them, and most importantly why you want to take your code from version A to version B, it really helps you build a better sense of "I should architect this code that way because of X principle". For instance, I just flipped to a random page for "Replace Constructor with Factory Method". He spends about half a page explaining how to do the refactoring, half a page on why you'd want to, and three pages of examples that clarify both making the actual code changes and why you'd want to. After reading it you have a much better understanding of when you would be better off with a factory method, and you can use that knowledge even when you're writing new code, not just to convert an existing constructor. If Fowler isn't your speed another really popular title (that I haven't gotten around to reading) is Code Complete. And there are plenty of other good ones, but the point is that if you learn from really experienced people what patterns have costs and benefits, it equips you much better to make architectural decisions on your own.
__________________
Loramin Frostseer, Oracle of the Tribunal <Anonymous> and Fan of the "Where To Go For XP/For Treasure?" Guides Anyone can improve the wiki! If you are new to the Blue server, you can improve the wiki to earn a "welcome package" of up to 2k+ platinum! Message me for details. | |||
|
#7
|
|||
|
Unless you're doing cool math god and calling the hardware directly, there's not a huge performance difference in modern C compilers i guess, based on my most anecdotal cursory experience between your examples
So it kinda boils down to readability and management | ||
|
#8
|
|||
|
all the code in the world cant spark this blunt in my hand. not even the leetest russian ukrainian czech datapirate coin miner on earth can blaze me up rn. perspective wisdom.
sometimes the best option is the 1 that "just werks" | ||
|
#9
|
|||
|
what if someone makes a blunt delivery by drone app tho?
| ||
|
|
|