vendredi 4 décembre 2020

Is there a common practice on how to utilize Object Oriented Programming?

I have seen two overall practices used in OOP. Is any of the following practices known as the "common practice", or does it matter at all? The examples is based on basic Game Design written in pseudo Python.

Option A:

Class Entity:

    shitton of states a,b,c,d,e,f,g,h,i;

    def render(args):
        ...
    def collsion(args):
        ...
    def move(args):
        ...
    def attack(args):
        ...

Option B

class Entity:
    Basic states a,b,c
    
    def move(args): # Advanced movement could be handled with a seperate class

class Entity_UI:
    Basic Graphics states a,b,c

class Renderer:
    def render(Entity, args)

class Collsion:
    def collision(entity_a, entity_b, args)

class Attack_Handler:
    def attack(entity_a, entity_b, args)

Examples are not complete (lacking inheritance etc.), but you should grasp the idea between the differences of OOP practices. Personally i disgrace Option A, leaving each class to have a clusterfuck of states which eventually can leave to spaghetti code. However i feel like Option B can feel a little over-engineered at times. Is there a common practice in the industry, and if not, what do you prefer and why?

Aucun commentaire:

Enregistrer un commentaire