Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should an abstract class have at least one abstract method?

Tags:

Is it necessary for an abstract class to have at least one abstract method?

like image 694
java_geek Avatar asked Feb 17 '10 18:02

java_geek


1 Answers

The subject of this post and the body ask two different questions:

  1. Should it have at least one abstract member?
  2. Is it necessary to have at least one abstract member?

The answer to #2 is definitively no.

The answer to #1 is subjective and a matter of style. Personally I would say yes. If your intent is to prevent a class (with no abstract methods) from being instantiated, the best way to handle this is with a privateprotected constructor, not by marking it abstract.

like image 194
matt b Avatar answered Nov 25 '22 14:11

matt b