0

Suppose we have 2 tables 'Departments' & 'Users'. There is also another table called 'UserDeps' for user<->department relation. For the first 2 tables we have 2 classes for domain objects. There is a layer in the app. for converting tables into objects and vice versa.

Now The Problem: I have a method like this: List GetDepartmentUsers(long depid);

My question is : Where do you put this method?

  1. As a static method inside 'Department' class? ( obviously syntax would be something like this :

List<Users> GetDepartmentUsers(long depid, DataHelper dh);

  1. As an instance method for every 'Department' object?

Department dep = new Department(depid);

DataHelper dh = new DataHelper();

dep.GetDepartmentUsers(dh);

Note: 'DataHelper' is a class which handles DB/SQL operations.

BHP
  • 443
  • 4
  • 13

1 Answers1

0

Without knowing the whole context, just based on what is provided, the second solution is better. A Department has Users, therefore, it makes sense to ask a Department to get the list of its Users.

The first one is not object-oriented. Because static method is just a function not a method in OO sense. Such functions kill the purpose of OO.

Nazar Merza
  • 3,365
  • 1
  • 19
  • 19