0

I remember reading (or hearing) somewhere a few years back that classes must have either an operation, an attribute and an operation, or at least an attribute as a mandatory requirement -- not empty. What I'm asking is whether it's a violation of the Software Engineering rules to have an empty class, or a class with either attributes or operations without the other.

I just want to make sure so that my class diagrams are correct for my project.

Thank you.

Ahmed Elsawalhy
  • 148
  • 1
  • 6
  • 10
  • 1
    Having an empty class is a violation of nothing, but usually there is no reason for one. Only operations/attributes is allowed by your definition, so what's the problem with it? – Jon Dec 10 '13 at 14:04
  • 2
    http://stackoverflow.com/questions/4035180/advantages-of-an-empty-class-in-c – xor Dec 10 '13 at 14:07
  • My question is clear and I'm asking for **expert** advice: "What I'm asking is whether it's a violation of the Software Engineering **rules** [...]." – Ahmed Elsawalhy Dec 10 '13 at 15:29

2 Answers2

2

You can certainly have a class with attributes but no operations and vice versa.

As for a class with no attributes and no operations - Most (all?) OO languages would allow this, but of course such a class wouldn't be terribly useful except perhaps as a base class of some sort.

Eric Petroelje
  • 59,820
  • 9
  • 127
  • 177
1

Engineering is all about breaking the rules and thinking outside the box.

An empty class, without properties (attributes, etc) or methods (operations, etc) is simply that: an abstract datatype which does nothing.

Many if not most type systems provide for such a thing, if one isn't predefined.

If you define your own, you should have a good reason for doing so. In C++ for example a class used as an object or tag in metaprogramming is often completely empty, because it only serves to carry information through the type system or function overloading at compile time, and ideally does not exist at runtime.

Potatoswatter
  • 134,909
  • 25
  • 265
  • 421