c# - What is the simplest way to change the behavior of a method during runtime? -
I have a class named My current idea is to use a What should I know, is it better to do this To put everything in a function, or to create a new class for each code that comes from Any advice would be appreciated. EDIT: Thanks for all the responses, I think I will use the proposed interface method by Alastair. However, this may be better suited on this site, Consider using it. A movement statement. E.g. So you will have many different behaviors that describe different movements. for example. then your enemy constructor may have Like Defniniton: This means that you can easily do different movement behaviors Can enemy , and I want many types of enemies, each
enemy will have different movement behaviors, for example, can be directly transferred directly to the player, maintain a certain distance, etc. What would I want to know, what is different behavior, preferably in a class?
switch , and to include all the behaviors in a method
public class enemy {full public} Health; Public damage; // etc etc go public zero (string type) {switch (type) {case "charge": chargeMove (); break; "Maintain" the case: keep uphold (); break; }} Private Zero Charges () {// Luggage} Maintaining Private Zero () {// Accessories} // All Behavior}
Enemy ? I would like to keep it in a square, so that all enemies can be well stored in
ilist without using any castings to use any particular task.
Public Interface ImpexBeihara {Move zero (Enemy enemy); }
Public class chargingActivator: IMovementBehavior {...} Keeping public squares should be used: ImovementBehavior {...}
Public enemies (IMVEIFTBehavior MovementBehavior) {...}
Comments
Post a Comment