educative.io

I feel the Admin class could be a God class

Discussion: I’m feeling the following Admin class described as example could be a God Class, since if we add operations requires admin in future, we need to put everything into the Admin class regardless of entities/use-cases.

I feel that violates the single responsibility principle. What do you think?

public class Admin extends Account {
  // spot here refers to an instance of the ParkingSpot class
  public boolean addParkingSpot(ParkingSpot spot);
  // displayBoard here refers to an instance of the DisplayBoard class
  public boolean addDisplayBoard(DisplayBoard displayBoard);
  // entrance here refers to an instance of the Entrance class
  public boolean addEntrance(Entrance entrance);
  // exit here refers to an instance of the Exit class
  public boolean addExit(Exit exit;

  // Will implement the functionality in this class
  public boolean resetPassword() {
    // definition
  }
}

An alternative idea I come up with was:

  • Rather than put those methods in the Admin class, we can create collection classes for DisplayBoard, Entrance, Exit, and ParkingSpot and implement those methods into the above classes.

  • We can create a Facade that checks the caller’s principle when invoking those methods.

I’m feeling this can be too detailed in a job interview.
I’m glad if you give me some feedback.

1 Like

Hi @Asayu,

In this scenario, the Admin class does not act as a God class. The sole purpose of the Admin class is to manage the physical entities of a Parking Lot. It has the functionality to add new entrances, exits, and parking spots, but it does not modify/update their information.

However, there can be multiple ways to achieve this. It’s all about designing and redesigning to come up with the most effective solution.

We hope Educative has inspired you to further your learning, and please drop us a note if you have any other questions or concerns. :slightly_smiling_face:

2 Likes

Hi @Saif_Ali

Thank you for the reply!

I understand that it is not a System Admin class but Parking Admin class.
in that case, that makes sense to me. :slightly_smiling_face:

1 Like