Understanding Class Instantiation vs. Non-Instantiation

0
2
Asked By CuriousCoder42 On

Hey everyone! I've been diving into class instantiation and wanted to clarify something I often hear: that a class needs to be instantiated to 'come to life', otherwise, it's just a model. I have a specific case in my game where I have a `CalculMouvement` class that only calculates movements and an `ApplicationDesMouvements` class that applies them. These classes don't necessarily need to be instantiated since they serve a purpose without being objects. My question is: how does the programming language interpret a class that's never instantiated compared to one that is? Thanks for your help!

1 Answer

Answered By TechWhiz99 On

The way a class is interpreted can indeed vary by programming language, but generally speaking, when you don’t instantiate a class, it simply means that its methods and functions exist in your code but aren’t bound to any specific instance. This means that any static methods would essentially just work like normal functions without needing an object to call them. In your case, if your movement class has no instances, it won't hold any data in memory — it just adds to your program's size without actively contributing to functionality as an object would. But everything stays functional as long as it’s executed correctly!

GameDevGuru -

Got it! So, the functions are still there, but they don't actively manage any data unless called through an instance. That makes sense!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.