Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How crazy should I get with turning things into objects?

I'm still new to OOP, and the way I initially perceived it was to throw alot of procedural looking code inside of objects, and think I'd done my job. But as I've spent the last few weeks doing alot of thinking, reading, and coding (and looking at good code, which is a hugely under-rated resource), I believe I'm starting to grasp the different outlook. It's really just a matter of clarity, simplicity, and organization once you get down to it.

But now I'm starting to look at things as objects that are not as black and white a slamdunk case for being an object. For example, I have a parser, and usually the parser returns some strings that I have to deal with. But it has one specialized case where it has to return an array, and what goes in that array and how it's formatted has specialized rules. This only amounts to two lines plus one method of code, but this code sticks out to me as not being cleanly fitting in the Parser class, and I want to turn it into its own "ActionArray" object.

But is it going to far? Has OOP become a hammer that is making me look at everything like a nail? Is it possible to go too far with turning things into objects?

like image 382
Jeremy Smith Avatar asked Apr 04 '11 16:04

Jeremy Smith


1 Answers

It's your call, but you should think of objects as real life objects.

Take for example a car. You could describe a car with different objects:

  • Engine
  • Wheels
  • Chassis

Or you could describe a car with just one object:

  • Engine

You can keep it simple and stupid or you can spread the dependency to different objects.

like image 188
Kevin Avatar answered Sep 25 '22 17:09

Kevin