Do You Only Create Classes for Code You Meant to Repeat?

Learning Python starts fun, till you get to object-oriented programming. After a fun-filled introduction involving cats and dogs, the so called lesson on OOP ends abruptly. You are left in a confused state. How do I use OOP in my own code? When should I use it?

In this article, I’ll address a smaller part of the question. Do you only use OOP to avoid repeating code? The answer is a resounding no.

The primary reason for using OOP is to make design of large applications easier. You don’t start laying down bricks the moment you think of building a house. You plan the layout, lay down the foundations, make sure you’re complying with regulations, and only then work inside whatever wiggle room you’ve got.

Similarly, if you decide to build a social network, then you’d first have to decide what features you’re going to build, and how. Do we allow people to post? Can they befriend others?

Finally, how do we break this down into smaller parts so that while building the kitchen, we don’t have to worry about the bedroom? In short, when Sam builds the ability to post, can Harvey work on another feature without stepping on each others’ toes?

Although code re-use is a benefit of object-oriented programming, but designing a large application is a much bigger benefit.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Site Footer

Sliding Sidebar