3 ms·
Being written in an object-oriented language doesn't make code object-oriented. I could write Java using classes as (namespaces for stateless functions) XOR (st
by bccdee 5y ago
Being written in an object-oriented language doesn't make code object-oriented. I could write Java using classes as (namespaces for stateless functions) XOR (structs with no methods), and while it'd still technically all be objects and methods, in practice it wouldn't embody the spirit of OOP at all.
It is in keeping with the spirit of OOP to wrap up different entities' data in separate objects and have them interact with each other through methods. Exposing all of every entity's data to the world and letting unaligned actors unilaterally mutate many entities' state with no middle man is very un-OO, even if you dress it up in classes and methods.
- samsquire 5y agoFunctions grouped with data is inherently OOP. Even if you don't interact with a graph of objects in a class, you're still using OOP if you define methods on your class and use those methods to interact with fields.
- bccdee 5y agoA method on a class is just syntactic sugar for a function with an argument. It takes more than just "the presence of methods" for something to be OOP.
- samsquire 5y agoIsn't the grouping of methods with data a core fundamental principle of OOP? Even if it is syntactic sugar, Variables, Types, Classes, functions, method calls, structs are just syntactic sugar too. It just so happens that the syntactic sugar of grouping functions with data is OOP.
- deleted 5y ago[deleted]
- jayd16 5y ago>Exposing all of every entity's data to the world and letting unaligned actors unilaterally mutate many entities' state But that is NOT the pattern. Entities are ids, they have component tags that opt entities into some functionality and the systems encapsulate and track the mutable state that system controls. If you want to start sharing ownership of mutable state, that basically comes down to an implementation detail. Unity's ECS system does NOT let "unaligned actors unilaterally mutate many entities' state with no middle man." One could perhaps implement it that way if they so choose. It's just a matter of taste because, again, the design pattern is not inherently OO or non-OO.
- bccdee 5y agoDon't systems sometimes have to access each other's components to do work? Isn't any given component exposed to all systems, and not merely one?
- jayd16 5y agoIts a bit of an implementation detail I would say. If you use a single thread and explicitly order your systems then its probably possible to have fully accessible global state. Unity, for example, encapsulates the actual component data and uses a fairly complex API around command buffers to schedule readonly and read/write commands across many threads.