OOP design question: Problem: I have a GOD class i...
# announcements
s
OOP design question: Problem: I have a GOD class in my project which consist of more than 40 to 50 functions which belongs to different services. What I want to achieve: I want to move unique functions to dedicated subclasses and common functions to a parent class. Now the GOD class is injected in many classes. Can someone suggest me a design pattern where I don’t have to individually inject all these
SubClass
but a factory which will give the instances of these
SubClasses
and also provide access to the common functions which are in the parent class. Is it possible?
Copy code
class GodClass {
    fun common(){}
    fun a(){}
    fun b(){}
    fun c(){}
    fun d(){}
}

abstract class ParentClass {
   fun common(){}
}

class SubClass1: ParentClass {
    fun a(){}
}

class SubClass2: ParentClass {
    fun b(){}
    fun c(){}
}
b
my first question would be: do you really need inheritance? can't you just inject ParentClass to subclass?
e
a second question would be: do you really need a class? Does it have state? Do you use overrides in any meanigful way?
2
s
@bitkid I guess that make sense to get access to the common functions. But the 2nd problem is I need a design pattern which will provide me the instance of the subclass in particular classes. I don’t want to inject the Subclasses directly everywhere.
@elizarov The GOD class is an
AnalyticsTracking
class basically. I am just trying to break down the GOD class into different mini classes with dedicated analytics functions for a particular feature. There are common analytics functions used by different features in the project. I am not overriding any functions. I am just copying all the unique analytics functions to their dedicated feature classes and moving common analytics functions to a common class.
Solved the problem using Facade design pattern. Thanks for the help! @bitkid and @elizarov