Answer the question
In order to leave comments, you need to log in
Abstract and simple models?
Good afternoon. I apologize right away if this question seems stupid and inappropriate to someone.
How it is implemented now:
As I see the implementation:
Problem:
There is a common class (the first - main - class), which is inherited by many other classes and, of course, the extra code that is in this class has a bad effect on the performance of the entire application. There is another class (second class) that inherits and which is abstract for other functionality. But in this abstract class, methods are required that are common to all the functionality that inherits it, but as you know, an abstract class should not contain implementations. And I need this class to call it and another model, and this cannot be done through new.
Question:
How to deal with the second model so that its object can be called, but also that all other models that use it (extends) implement the necessary methods without fail?
Thanks for answers.
Answer the question
In order to leave comments, you need to log in
1) Abstract classes can, and sometimes even must, contain an implementation, perhaps you are confusing abstract classes with interfaces where no implementation is allowed.
2) At the expense of extra code - in order not to drag everything along the inheritance tree - divide it into several logical traits (trait) and include them as needed. Just they serve for common methods and properties, which, nevertheless, are not always descendants of the same class. For example, I wrote the Singleton trait, which would be stupid to inherit, since this is only one aspect of its functionality, and inheritance is not suitable here.
Concerning "as it is known the abstract class should not contain implementations" - can.
As for everything else, a well-written question is half the answer.
If you don’t be too smart and do it according to the given conditions, then you can make Model 2 non-abstract, objects of its type can be created and Model 2_1, to which you can add abstract methods and from which Models 3 and 4 will be inherited.
If you try to do it even simpler, then you can write what problem from the real world you are trying to solve and you will probably be prompted for a more correct division into types.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question