Sometimes a class isn’t worth it.

Not everything deserves to be a class.

If you have a class with a few methods but no data elements, it is probably better implemented as a method in another class. After all, without methods, what does it really represented?

Occasionally you’ll see these things, such as a Calculator class, that just consists of complex logic for performing some calculations. Of course, this begs the question, calculations on what? And as soon as you figure that out, you may wonder how that thing is modeled, and whether these calculations should live closer to that object.

These classes are often named after verbs.

In another example, take a class named “Shipper”. Its job is to ship something. Ship what? An order. Ah, it’s an OrderShipper. Or wait, maybe ship() should be a method inside the Order class.  So my_order = new Order(”pair of shoes”); my_order.ship(”123 Mockingbird Lane”); and so on.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: