Object-Oriented Programming
@deborah kurata pluralsight

Object-Oriented Programming

Writing clean code is always been a difficult task and that's because many of us lack the knowledge of object-oriented programing.

In this article lets discuss how can we write some clean code by applying OOP in our code, so let's get started.

The following are some steps to be followed when we go about writing code.

No alt text provided for this image


Let's take them one by one.

Identifying Classes :

No alt text provided for this image

We need to first identify business entities from the requirements / Spec, this is important because these are going to become your classes and their behaviors.

NOUNS - Will be your classes

VERBS - Will be their behaviors

These not going to be straight forward hence be careful, these are also going to help to identify your properties of the classes.


Separating responsibilities :

No alt text provided for this image

This is a step where most of the developer's miss to align with, this is a very important step, a class shouldn't be doing too many things, this maximizes coupling ( interdependency ) and reduces cohesion.

We should be aiming to minimize coupling and maximize cohesion, this is going to make our code lean, relevant and unit testable.


Establishing Relationships :

No alt text provided for this image

Once we complete separating responsibilities we will be left with classes yet relationships yet to be established, we shall establish the connections in this step.

Classes may be connected with different types of relationships like Uses a, Has a and Is a

Uses a: This a collaboration relationship in which a class collaborated with another class does some computation.

Has a: This is a Composition relationship in which a property of the class is made up of another class.

Is a: This is a relationship which is made up of ( Inheritance ) where a child class is a subset of the main parent class.


Leveraging reuse :

No alt text provided for this image

One important quality of a good Object Oriented code is code reusability, code has to crafted by taking these into consideration.

We need to identify if there are common codes and consider moving those into a commonplace like a utility class.

No alt text provided for this image


We need to check if there are any Is a relationship ( Inheritance ), In this, we can move the commonly shared code to a parent class and make the child classes inherit from it, thus leading to code reusability.


Happy coding !!

Bro this is just awesome. Put in simple words. Superb bro. Keep going. Keep doing good. Awesome.

To view or add a comment, sign in

More articles by Praveen Gnanadevu 🚀

  • Mediator design pattern ( Behavioral )

    This is a behavioral design pattern, has the name says mediator this design pattern facilitates communication between…

  • Iterator design pattern ( Behavioral )

    This is a behavioral design pattern, this design pattern is used to build the functionality of accessing elements one…

  • Interpreter design pattern (Behavioral)

    This pattern falls under behavioral design pattern, has the name says this pattern is used in solutions where we need…

  • Command design pattern (Behavioral)

    This is a behavioral design pattern, this design pattern is the best fit when we have to design something which a list…

  • Chain of responsibility design pattern

    This is a behavioral design pattern, this design pattern can be used to create a chain of objects which a request goes…

  • Proxy design pattern ( Structural )

    This is a structural design pattern, this pattern as the name says it acts as a front-facing interface or proxy to an…

  • Flyweight design pattern ( Structural )

    This is a structural design pattern, it helps reduce the overall memory consumption of the application by sharing…

  • Façade design pattern ( Structural )

    This is a structural design pattern, this pattern is used to provide a simple interface for a complex set of…

  • Decorator design pattern ( Structural )

    This design pattern is used to extend or add features to an existing class by wrapping a decorator class around it and…

  • Composite design pattern ( Structural )

    This is a structural design pattern, It's used when we are working with structured hierarchies. Composite pattern is…

Others also viewed

Explore content categories