floor icon indicating copy to clipboard operation
floor copied to clipboard

Allow Mixins

Open idkq opened this issue 3 years ago • 5 comments

I'm getting the error below and assume it is expected. I kind of need to use mixins. Can we put as feature request?

[SEVERE] floor_generator:floor_generator on lib/db/database.dart:
Entities and views are not allowed to inherit from mixins.

idkq avatar Feb 22 '21 00:02 idkq

Hi! What's your use case for mixins in database entities?

vitusortner avatar Feb 22 '21 19:02 vitusortner

I have entities that inherit from another generic class. The generic class allows me to access common fields across the board such as name & id. A few (a subset) of these entities share common fields that I would like to be able access in a sound manner (ensuring code linkage) in the same way I access the generic class. If I don't use mixins, I have no option but to get the fields by string, which can eventually break the code.

Example

class Animal{int getAge()} class Dog extends Animal{int age} class Cat extends Animal{int age} class Bird extends Animal{int age; int flyingTime;} class Parrot extends Animal{int age; int flyingTime;}

I can: print(Animal().getAge())

I cannot: print(FlyingAnimal().getFlyingTime())

I believe I could use multiple levels of inheritance but haven't tried yet and not sure what is the rational to prevent the use of mixins as it would make more sense in my case to inject the methods I need. Another option is to add getters to a new generic Dao, but seems very entity/instance related to me.

idkq avatar Feb 23 '21 18:02 idkq

I also used mixin in entity to apply EquatableMixin of equatable package. I know I can extends from Equatable class, but the use of EquatableMixin leaves the freedom to inherit from other classes.

It would be helpful if these limitations were stated in doc. I did not imagine that the application of a mixin, without fields, was not allowed.

Mabsten avatar May 17 '21 20:05 Mabsten

I also used mixin in entity to apply

SUNbrightness avatar Nov 08 '21 09:11 SUNbrightness

I also want to use Equatable library in my project just to not having to override == operator, hashCode and toString.

BetterB0y avatar Mar 25 '22 12:03 BetterB0y