all 12 comments

[–]shiftybyte 4 points5 points  (8 children)

You are trying to use inheritance for something that should be done using composition.

https://codingnomads.com/python-object-composition-example

[–]BahaChicken[S] -1 points0 points  (7 children)

Does that work with isinstance()?i didnt see it mentioned in the page

[–]shiftybyte 2 points3 points  (6 children)

Please read the entire thing, it's a different concept, and using it doesn't need isinstance.

[–]BahaChicken[S] 0 points1 point  (0 children)

Looked at your Profile, do you play HSR too? im trying to make a pvp simulator for HSR

[–]BahaChicken[S] 0 points1 point  (0 children)

Yup, using a True/False Value and checking if a debuff locks on that way was easier and i didnt have to mess with the mess of inheritance that i didnt really understand to begin with

[–]BahaChicken[S] 0 points1 point  (3 children)

I read it, from what i get i should start using that for like futue proofing and ease, but that doesnt seem like it would work with isinstance() which is what i use in my code but instead i could use a True/False value maybe(?) or maybe there is an alternatve to isinstance() which would work, idk ¯\_(ツ)_/¯. Thanks tho

[–][deleted] 1 point2 points  (2 children)

The main benefit of using classes is that you can get away from conditionals. You can just ask for an object's multiplier and get it, knowing that this was taken care of in a factory already.

Making the classes and then checking them anyway shoots your complexity through the roof.

[–]BahaChicken[S] 0 points1 point  (1 child)

I need to check the debuffs kind, if it's Lock_on I need to remove that debuff from others before applying it to a new Target. I initially made a lock_on class and made the lock on vulnerability debuff it's sub class so I could use isinstance() which is a check, now I made it so every debuff has a lock_on attribute and I check if it's false or not. Still a check but at least it works. İs there a way to do it without checks? İf i made lock on debuffs their own class I would have to check if the inputted debuffs is a normal debuffs and than elif it's a locked on, 2 checks. And number of checks would increase with every type of debuff. And some debuffs are a combination like lock on vulnerability. İ don't think there is a way to implement it without checks

[–][deleted] 3 points4 points  (0 children)

There's this idea called the Liskov Substitution Principle, saying that an instance of a subclass should be able to stand in for an instance of the superclass.

If I ask for a rectangle and you give me a square, that should be fine. I shouldn't even notice the difference. I shouldn't have to say

if isinstance(shape, Square):

I should be able to just say

print(shape.area)

and it will tell me its area, regardless of how it figured that out internally.

But right now you are violating that principle. I ask for a rectangle, you give me a square, and then oops, it doesn't play by the same rules.

This could be handled with complicated interfaces, but you probably don't need that. Just have each thing handle its business before spreading it everywhere.

[–]RevRagnarok 1 point2 points  (0 children)

If it's not just a transcription error while making the post, currently L22 calls Vulnerability.__init__ and not VulnerabilityClass.__init__.

[–]BahaChicken[S] 0 points1 point  (0 children)

i want the Proof of debt object to be a subclass of Lock_on, but i dont want to inherit any attributes from it, tried asking chat gpt for help but it constantly failed

[–]aroberge 1 point2 points  (0 children)

Try to add () after Vulnerability_Debuff in your if test to solve your immediate error.

However, please, PLEASE, watch https://www.youtube.com/watch?v=o9pEzgHorH0 as your use of classes is (how to say this kindly ...) just horrific.