Mixin or not to mixin. #6293
Replies: 2 comments
-
Currently C# doesn't support what you are describing natively, I asked for something like this here: #5897 In the meantime, you can do it manually: add "feature" type fields to your |
Beta Was this translation helpful? Give feedback.
-
You don't need mixin. That pattern was a specific solution for C++. The same can be achieved by simple normal composition. The only difference is that: instead of
A more advanced design is component-based entities, which an entity has a collection of feature components, and the components can be added or removed dynamically. This is typically used in game engines where customization and extensibility is highly needed. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I am trying to make game and wondering what is best design for my problem.
Let say I want to make
MyPlayer class which can play sound, produce light and fall by physics.
MyTeamPlayer can play sound and move by Ai system.
MyCar moved by Vehicle system play sound and produce light.
So what I am thinking is to implement every feature as seperate clean code then compose my classes with these features. Features are
AudioSource.
LightSource.
Rigidbody.
Agent (AI).
Vehicle.
Will mixin help me or may be use something else (may be code copy for every class 😊)
Please note
-I want each feature to have its own fields.
-It will be awsome to call feature constructor and destructor automaticlly when my class get created or destoyed( so i add MyPlayer to physics system automaticlly when get created without extra setup inside MyPlayer) .
Is it possible to do it currently with clean code or I should wait mixins to get improved,or wait for multi inheritance support ( with field sharing support), or may be you make something called feature.
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions