lundi 20 janvier 2020

Breaking down a GOD class to single responsible classes

Problem:

I have a GOD class in my project which consists of more than 40 to 50 functions that belong 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?

class GodClass {
    fun common(){}
    fun a(){}
    fun b(){}
    fun c(){}
    fun d(){}
}
abstract class ParentClass {
   fun common(){}
}
class SubClass1: ParentClass {
    fun a(){}
    fun d(){}
}
class SubClass2: ParentClass {
    fun b(){}
    fun c(){}
}

Aucun commentaire:

Enregistrer un commentaire