Skip to main content
added 585 characters in body; added 36 characters in body
Source Link
Ewan
  • 79.9k
  • 5
  • 83
  • 179

Yes its a code smell.

If you have empty classes with no logic, then it suggests that somewhere in your code you have conditional logic which checks what class an instance is.

eg.

if(x is Dog) then y

Also it might suggest that you have an ever increasing number of empty classes, Cat, Dog, Cow, Sheep etc etc

These kind of things should normally be replaced by an enum or string "Type" property on the parent object.

Of course I need to add the usual caveat. "code smell" != bad code. Its just something that is seen often in conjunction with bad code.

Also it suggests to me that you are applying an OOP approach to business rules, which isnt always a good idea.

Your pet grooming business example shouldnt have dog and cat objects with a groom method. I would expect it to have a Service class with no methods.

Service
{
    Id;
    CustomerId
    Type;
    Price;
    Date;
    Status;
}

A Customer would book a Service Type= "Dog SuperGroom" and you would have classes such as LateServiceEmailer where your OOP would come into affect.

No Business wants to hear "Oh we cant make that change because a Fish isnt an animal.

Yes its a code smell.

If you have empty classes with no logic, then it suggests that somewhere in your code you have conditional logic which checks what class an instance is.

eg.

if(x is Dog) then y

Also it might suggest that you have an ever increasing number of empty classes, Cat, Dog, Cow, Sheep etc etc

These kind of things should normally be replaced by an enum or string "Type" property on the parent object.

Of course I need to add the usual caveat. "code smell" != bad code. Its just something that is seen often in conjunction with bad code.

Yes its a code smell.

If you have empty classes with no logic, then it suggests that somewhere in your code you have conditional logic which checks what class an instance is.

eg.

if(x is Dog) then y

Also it might suggest that you have an ever increasing number of empty classes, Cat, Dog, Cow, Sheep etc etc

These kind of things should normally be replaced by an enum or string "Type" property on the parent object.

Of course I need to add the usual caveat. "code smell" != bad code. Its just something that is seen often in conjunction with bad code.

Also it suggests to me that you are applying an OOP approach to business rules, which isnt always a good idea.

Your pet grooming business example shouldnt have dog and cat objects with a groom method. I would expect it to have a Service class with no methods.

Service
{
    Id;
    CustomerId
    Type;
    Price;
    Date;
    Status;
}

A Customer would book a Service Type= "Dog SuperGroom" and you would have classes such as LateServiceEmailer where your OOP would come into affect.

No Business wants to hear "Oh we cant make that change because a Fish isnt an animal.

Source Link
Ewan
  • 79.9k
  • 5
  • 83
  • 179

Yes its a code smell.

If you have empty classes with no logic, then it suggests that somewhere in your code you have conditional logic which checks what class an instance is.

eg.

if(x is Dog) then y

Also it might suggest that you have an ever increasing number of empty classes, Cat, Dog, Cow, Sheep etc etc

These kind of things should normally be replaced by an enum or string "Type" property on the parent object.

Of course I need to add the usual caveat. "code smell" != bad code. Its just something that is seen often in conjunction with bad code.