• Latest
  • Trending
  • All
  • News

The Importance of Decoupled Objects in OOP

July 10, 2017
5 Vital Car Cleaning Tools To Make A Car Look Brand New

How Exterior Detailing Services Can Enhance the Look of Your Vehicle

January 21, 2024

The Ultimate Guide to Rebuilding a Transmission – Everything You Need to Know

December 10, 2023
5 Weekend Travel Tips for Lasting Joy With the Family

Preparing Your RV For Storage – Essential Steps to Take

November 21, 2023

5 Reasons Why Regular Auto Repair Services Are Crucial for Your Vehicle

November 21, 2023
Comparing the Services of Open Vs. Enclosed Car Shipping

Comparing the Services of Open Vs. Enclosed Car Shipping

November 20, 2023
Heavy Vs. Light Duty Towing: Knowing The Kind of Truck You’ll Need

Heavy Vs. Light Duty Towing: Knowing The Kind of Truck You’ll Need

November 11, 2023
6 great reasons why vehicle owners won’t be stranded when calling out a local locksmith

6 great reasons why vehicle owners won’t be stranded when calling out a local locksmith

October 27, 2023
Six Reasons to Buy a Classic Corvette

Six Reasons to Buy a Classic Corvette

October 20, 2023
Top 5 Signs of Alternator Problems

Top 5 Signs of Alternator Problems

October 10, 2023
7 Common Engine Rebuilding Mistakes and How to Avoid Them

The Benefits of Reliable Auto Repair Services You Can Trust

October 9, 2023
Practical Car Interior Gadgets to Upgrade Your Ride

Top Reasons Why Used Cars Are a Better Investment

July 2, 2023

Essentials of Handicap Vehicles

June 20, 2023
  • Guest Posts
  • Advertise
  • Contact
  • Privacy Policy
Saturday, June 28, 2025
  • Login
Tech Featured - Automotive
  • Home
  • Gadgets
  • Automotive News
  • Interesting Topics
No Result
View All Result
Tech Featured - Automotive
No Result
View All Result
Home News

The Importance of Decoupled Objects in OOP

July 10, 2017
in News
0
79
SHARES
226
VIEWS
Share on FacebookShare on Twitter

In OOP (object oriented programming) it’s important to remember why you are building an application with objects instead of mere functions (procedural programming). Sometimes programmers will treat objects more like functions which completely defeats the purpose of objects in the first place! The purpose of this post is to explore the real benefit of OOP and how to structure your models appropriately.

What is a decoupled object?

Contrary to the novice OOP programmer’s belief, an object is much more than a collection of data members and related methods. It’s important to remember that an object embodies data and methods that pertain only to itself. The term “decoupling” is used to identify the separation of software blocks that shouldn’t depend on each other.

Why is it important to decouple objects?

Let’s say that we have a Car Class with the methods driveForward(), stop(), turn(), honkHorn(), and changeLanes(). This object has a poor design because one of the methods, changeLanes(), might depend on a Street class. What if you were trying to reuse this class for a car that only drives off-road? In this case, the changeLanes() method is completely meaningless to your object instantiation. Furthermore, if the turn() method were to reference the changeLanes() method, the entire object would start to seem too specific to instantiate and work with an off-road car. In addition, if a change is made to the Street class, it’s very likely that the Car class will also have to be modified. Since Car has a method that depends on another object, this object is said to be “coupled” (which is what we are trying to avoid).

How to decouple objects

To create what I call “purified objects”, we need to completely decouple them in such a way that all of their fields and methods are specific to what the object can do in any circumstance. To decouple the Car class, you would want to move the changeLanes() method to another object that interacts with Car, like CityDriving. This new object acts as a mediator because it uses the Car class for special circumstances without tainting its pure definition.

When designing your object models, ask yourself “are these objects purified? Are they decoupled?” If you religiously ask yourself this question when creating new objects, not only will you end up creating much cleaner code, you’ll also spend less time re-factoring. Good luck!

Tags: ImportanceObjectsOOP
Share32Tweet20Share8
  • Trending
  • Comments
  • Latest

John Christie Electric Generator – Generates 24 Kilowatts Of Free Electricity

November 21, 2016

How to Use a Magnetic Generator to Get Rid of Your Electricity Bill

November 21, 2016

Buying a Gazebo – How to Install a Gazebo on Grass

June 8, 2017

The Environmental Benefits of Automobile Recycling

0

Automotive Fasteners – A Number of Items Included on the List

0

Drag Racing – The Perfect Launch

0
5 Vital Car Cleaning Tools To Make A Car Look Brand New

How Exterior Detailing Services Can Enhance the Look of Your Vehicle

January 21, 2024

The Ultimate Guide to Rebuilding a Transmission – Everything You Need to Know

December 10, 2023
5 Weekend Travel Tips for Lasting Joy With the Family

Preparing Your RV For Storage – Essential Steps to Take

November 21, 2023
Tech Featured - Automotive

Navigate Site

  • Guest Posts
  • Advertise
  • Contact
  • Privacy Policy

Follow Us

No Result
View All Result
  • Home
  • Gadgets
  • Automotive News
  • Interesting Topics

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In