Click here to Skip to main content
13,511,029 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


18 bookmarked
Posted 4 Dec 2017

Object Oriented Programming Concepts for Professionals Part 1

, 12 Dec 2017
Rate this:
Please Sign up or sign in to vote.
Object-oriented programming concepts for those who are writing professional software i.e writing code for money

Let me tell you a story,

Once there was a skilfull juggler in town. He performs pro-bono shows in the streets and earned pennies. Impressed by his skills someone gave him the advice to apply for large theatre or in a circus where he can earn real money.

The juggler was afraid because he didn't want to be in the presence of a huge audience and secondly he was afraid of bureaucratic nature of circus management where he has to answer to his boss. But due to pressure from economic conditions, he applied for a circus job and called for the interview with the circus manager.

Circus Manager: Welcome

Juggler: Thanks

Circus Manager: do you know how to juggle balls?

Juggler: Yes I can.

Manager: Can you juggle with knives

Juggler: Yes

Manager: Can you juggle with knives and balls at the same time

Juggler: Yes I can

Manager: Can you juggle with 5 balls at the same time

Juggler: It’s a piece of cake

Manager: Hmm, can you juggle with 7 at the same time

Juggler: Yeah I can, Do you wanna see it?

Manager: Nopes.

Juggler: Do you wanna see any of my performance that I told you?

Manager: No I don’t have time.

This also happens when we go for programming interviews. Many programming interviews focus more on the academic knowledge and judge everybody through questions. Everybody checks how knowledgeable you are but nobody will check how competent you are: How well you can apply your knowledge to solve problems.

I have faced these interviews and ace almost all of them--10 years ago. But after years of programming experience now I have a deeper understanding of the same concepts and now I sometimes laugh at my previous knowledge.

So, I have written this article from my personal experiences i.e the way I see object-oriented programming. If you think by reading the content of table that: "Yeahh... I know inheritance or I know what is abstraction and there is nothing new here." You should give it a try, I bet you that you will rarely find the textbook definitions.

If your definition of professional means frameworks, patterns and architecture then I have written a separate article for that or article on design patterns. This article is about the very basic concepts of object-oriented programming and how can you use them in your project and in your environment.

If you need text-book definitions and/or proper definitions and definitions that you can include in your presentations and scholarly papers then there are other articles available. Maybe you think that I have mistaken some concepts. Maybe!. Believe me, it is not wrong. It’s the way I use them and it’s my perspective. I have mentioned their benefits as well as drawbacks.

If you think that using the concepts my way can bring harm to this world then you are welcome to mention them in the comments section and we will discuss them. Here is the outline of the article:


In the second part of the article  you will learn outside the 'class' concepts as follows:

  • Outside the 'Class' Concepts
    • The Primary Goal Outside
    • Association: How it is Better Than Inheritance
    • Inheritance
    • Method Overriding
    • Abstraction: The Tool That Helps you Develop Mega Software Systems
    • Interface: First Tool of Abstraction
    • Closer Look at Interfaces
    • Abstract Class
    • Difference between Generalization and Abstraction
    • Difference between Generalization and Composition
    • Polymorphism
    • Protected Variation: Ulitmate Goal
  • Outside the workbench- Your Team
  • Tools of communication with Team
    • Your code as tool
    • Your comments
    • Diagrams
      • UML
      • Flowcharts
      • Data Diagrams
  • Tools of communication with your boss
    • High-Level Summaries
    • How to give Estimates
    • How to deal with meetings
    • How to educate your boss


Before moving please note the following that this article is not for:

  • Developers who are preparing for a job interview
  • Who are looking for text-book definitions
  • Who are looking for current technologies and not good old concepts
  • People who are old and rigid

We often start our journey in programming by writing basic flow elements like variable initializations, conditional statements, loops and etc. Then we move on and learn concepts of functions, passing arguments, global and local variables and so on.

Easy stuff for beginners.

Now if you are using good old ‘C’ language then you will move on to pointers and memory management. With C programming knowledge you can conquer the world. You can work in embedded systems. You can write a new operating system or invent new programming languages. But this will take time and you will have to be fluent in pointers and memory management.

For everyone else who is not serious about learning C then you have to be fluent in object-oriented programming. Because if you are using Java, C#, python then object-oriented is a must. If you are using JavaScript or PHP then object-oriented programming can help you a lot.

As you can see it is necessary to know about object-oriented programming for everyone(I am a bit conservated here let’s say 90% of developers).

Who is This Article for? Students, Amateurs or Professionals?

Everyone! I mean everyone who studies computer science or programming knows about object-oriented programming. TRUE!

But do we fully grasp the concepts of OOP? Think about it.

The code that I have written at the start of my career and which I thought was a good quality code. Now when I see it today I feel vomiting and I hide it immediately before anyone can see it-yet I still see the developers making same mistakes.

Look getting work done is not enough. You can exploit the object-oriented programming languages like C# and Java and use them as a procedural language. Getting work done without thinking about the quality of code will not make you a professional software developer.

If you have good grades in courses related to object-oriented programming or if you have given all answers in an interview then you are still a long away from being a good object-oriented programmer. This article is for those who are currently writing software for money. Who have completed their studies and have at least 2 years of professional programming experience.

Why 2 years? Well at the start of your first job you are worried about proving yourself and learning the environment. For example, finding your tables and computer, knowing about the boss, learning the frameworks and tools that you never heard of in your studies. Once you get it done(which takes around 2- 3 years) now you are looking ahead. Now you are ready to take next steps.

A quick test to know if you are good at professional object-oriented programming

Think of any famous framework in any programming language(javascript, Java, C#, PHP, Python). Think about all the constituent in that framework.

If that framework is no brainer to you. If you know why ‘clojure’ is used or why a particular set of classes are used or you know why you have to use so many classes to accomplish a simple task. Then consider yourself good at object-oriented programming.

A word of caution here. Above I am asking about the ‘why’ question, not the ‘how’ question. If you just know how to create a file by using the ‘Stream’ classes. Or just know how to call jQuery methods then you are a consumer of good object-oriented design. You are not the producer yet.

Do you want to be that vast majority of developers who write only glue code and most often tied to a framework for years? When they change their job then they realize that nobody in the universe is using that framework anymore and they have to start all again. I call them the consumers.

To be a producer you have to be on the other side of the wall where developers who not only understand why there is more than one class to accomplish a simple task but they are the ones who create libraries and frameworks that are consumed by millions of developers each day.

Yes, it is true that at the start your framework or library is not going to hit the life of millions of developers but if you start today it will improve the life of one developer and that is you!

This will help you in two ways. It will help you to move up in the career ladder fast. You will become senior developer quickly and ultimately a great architect and system architect(provided that you choose to remain in technology instead of management).

Another benefit of mastering the object-oriented programming skills is that these skills will be with you for life. On the contrary, if you learn a particular framework and work on that framework for two, three or even five years. What happens if that framework is replaced by another fast and optimized framework then you will have to start from zero. 

Similarly what happens if you change your job and at your next workplace they are a different framework than your previous workplace. Your previous experience will be near to zero. But if you know object-oriented concepts and have applied them firmly in your work then you have that experience for the lifetime. You can always get leverage out of that object-oriented experience.

Where OOP stands in The Great Scheme of THINGS?

This topic is to remove major confusions. People in development still have confusion about processes, architecture, databases and a lot of other things like frameworks and build process and etc.

Where is this ‘OOP’ fits in the larger context of software development? Is it a process? Is it an architecture or something else? For example, if someone asks you: Is OOP good for extreme programming OR SCRUM or let’s say an embedded system? Or ask you this question “does n-tier architecture supports object-oriented programming?”

Well, I am feeling stupid right now by asking these question but there are people who ask these type of questions and they are still confused. Don’t trust me! You can ask any new developer the questions stated above and you will know.

Now, what will you say when someone asks you this basic question:“What is object-oriented programming?” Well if someone asks me then I will say that object-oriented programming is a development methodology. That was easy:) You probably know that!

Development Methodlogy

Let’s consider a developer named Jack. Jack is a new developer who has studied computer science or a related discipline from a college/university or online institution.

Jack know about object-oriented programming because he studied the course with the exact name:“object-oriented programming”. Jack believe this is the only way people write code. Jack doesn't know much about assembly language or C programming language.

Jack started his career with JAVA or C# as a programming language. The mishaps that happened with Jack is that he was born into the programming world when everybody is talking about object-oriented programming and it is the only paradigm that he sees everywhere. Jack has no interest in history so he doesn't know if there are other paradigms for development methodologies. Prior to Jack, there were other development methodologies that were so awesome.

Let’s take the paradigm of procedural programming. COBOL, Fortran, and Pascal were the default choices for any developer and before that assembly language programming was a must for every computer scientist.

Also, Jack doesn't bother to look around. Jack doesn't know there other fields where other types of development methodologies suits. For example, LISP a functional programming language and is used in artificial intelligence systems. Although it is not limited to that only and there are other applications where LISP can be used. Even today the procedural programming language ‘C’ is most suitable for embedded development.

So, let’s say goodbye to Jack for now.

Object-oriented programming is one of many development methodologies. It has nothing to do with development processes or architectural style.

Also, one can use any development methodologies with any development process. Similar is the case with architectural style. One can use any development methodology with any architectural style.

But, there are some methodologies that can best work with some development processes and architectural style. But no one is going to stop you if you try to break the established guidelines. After all, creativity is what a developer should be looking for.

Now, for the sake of completeness let us discuss the development processes, but this time for professionals only. Also, remember that the right process with the right methodology will lead to a good quality software code. Here is an example of how to use both together.

Inside-Out Strategy: This Will Make it Easy for you to Apply These Concepts

I will start with the internals of the core entity in object-oriented paradigm and that is the ‘Class’ and it’s representation in memory and that is the ‘Object’.

In the ‘inside’ strategy I will discuss only the internal of object and classes. Nothing more. If you do the basics right then everything else will be fine.

I will only discuss internals that is necessary to know for any professional developer. There are chances that you have learned these out of your own curiosity but I will share my experiences.

Once you mastered the internals of the class and objects then we will move to the ‘out’ strategy. This is where one object or class work in conjunction with other object and class.

‘Out strategy’ is a very important part. Because in order to achieve something bigger every object in your software code needs to communicate with each other.

There are a lot of principles and design patterns to achieve this inter-object communication but I will tell you the most important principle that you need to know at this stage.

After that, I will discuss that it is not only how your objects collaborate with one another but how you collaborate with others specifically your teammates and your boss.

This is an important point and many people ignore this but for professional developers who are working in a professional environment and not in a classroom will face these challenges.inside out strategy

Hence the inside strategy comprise of:

Class, fields, functions, constructors and static fields. I will explain an important concept of how objects are represented in memory. I will also discuss how to create the class that looks like created by a professional.

The out strategy consists of two concepts. The first concept is about how your classes interact with each other and the ideas that are essential for professionals. Second and the most important concept in ‘out’ strategy is how you communicate with every other human around you.

This means how to communicate your design ideas with your teammates. How to take your teammates onboard with your ideas and most importantly how to convey your ideas to your boss.

The last part is important because when you talk about improving the quality of your work or introduced methods that will improve the efficiency not in the short term but in the long term then everybody-- I mean everybody-- will resist it.

Nobody wants a quality code initially. They need the job gets done. In their heads, they think job to get done equals to quality code. This looks good initially but in the long term that code will grow and become rotten and then everybody in your team will feel the smell of that rotten code. To learn more about this click here.

There are tools to deal with that situation but for now--let’s assume that you want to know how to start software development with the right mindset.

Inside the 'Class' Concepts

Class: Your Tool for Capturing ideas

A class represents your ideas about ‘anything’. Textbook definition is that the class is ‘blueprint’. A class can represent a physical object like chair, screen, humans, animals. A class can represent a role: Student, Employee and etc.

A class can represent an abstract concept like maths concepts: Circle, Kalman filter, and others. A class is your idea of ‘anything’ and how do you want to represent your idea in the computer memory.

Object-oriented programming gives you tools to define your class. These tools are the class name, data, and behavior.

You can represent the data relating to your ‘concept’ in a class. That data is called attributes. It can be of any primitives data types. For example, it can be, int, double, float, long, byte, short, boolean or char.

A class also represent the behavior of your idea. The way you want your ‘idea’ or ‘thing’ want to behave. It is not necessary for you to create the behavior or data. It all depends on your idea. It is your choice if you want to create a class with behavior only or a class with data only or a mix of both.

You have made your choice and now let’s move on to the real thing that will transform your idea into a reality(in a computer memory)- the object

Object: The Real Thing

The only thing that exists in memory is an object. An object is created from the definition of class and here is the example of how the object is created:

MyClass theObject = new MyClass();

Objects are the real thing because they exist in memory. Let’s explore more on this. Consider the following code listing:

public class Automobile
int NumberOfWheels = 4;

int Weight = 200;

double fuelEfficiency = 1.2;

Now calculate how much memory the object of this class will take?

int is 4 bytes and double will take 8 bytes if you are using C# or Java. Therefore one object of this class will take 16 bytes.

If you create 2 objects of this Automobile Class it will take 32 bytes.

What if a naive developer fetches records from a huge database and created the objects for each record of ‘Automobile’. When will it run out of 4GB of memory?

No of Records that your memory can hold = 4GB/16

Hence after 67108864 records, the system memory will be filled up. In a professional environment, databases are usually way more size than this. I have seen a junior developer doing this kind of mistakes when they are new to object-oriented technology.

The solution for a junior developer is that you should use ORM framework for that and that will handle these issues for you by managing the memory.

Let’s consider another example of object:

public class Automobile
int NumberOfWheels = 4;

int Weight = 200;

double fuelEfficiency = 1.2;

static int countVehicles =33;


Now, what will be the size of one object? 20 bytes. What will be the size of 5 objects?

The answer is 84 bytes. 16*5+4 = 84. There will be only one copy of the static variable in memory. It does not matter how many objects you create there will be only 1 copy of the static variable that will exist in memory.

In addition to that, that single copy of the static variable is accessible to all the objects. It’s kind of a global variable. Yes, the bad-old global variable.

One thing that I learned from painful experiences is to avoid the use of global variables. As a program grow older, it is difficult to track that who is modifying the value of global variables. So always be careful when using static members in a class.

Class: Member Variables

Member variables hold the current state of an object. These are the data variables and they are also called instance variables. If they are declared with the static keyword then they are called Class variables. Well, you know all this--Don’t you?

The key to using member variables is how will you use them in your code. If you intend to use a member variable within a class then there are very few problems.

But if you want --maybe someday-- to expose your member variables outside the scope of your class then you should follow certain guidelines. Outside the scope means writing a class to disk in JSON format or a representing a database record or communication with another class.

For these outside reasons, people have developed getter and setter methods in Java and property type in C#. They are also called accessors. These accessors play an important role in frameworks and they are extremely useful concepts.

Consider C# as the programming language for the following example:

public class Automobile

int _weight = 200;
public int Weight

   return _weight;


   _weight = val;


Now what you are seeing is how most people use these accessor methods(get and set). There are a lot of things that you can do here. You can do any validation before setting any value, you can update or calculate any other value or you can store/retrieve a value from storage devices directly from here.

The most important thing that these accessors do is that they signal outside world (especially frameworks) that we exist. Through accessors, the outside world knows how many getters and setters are there and they will behave accordingly.

Here is an example of how an outside class can use accessors:

public void methodInAnotherClass()


Automobile theAutomobile = new Automobile();

theAutomobile.Weight = 300;

// retrieve

int currentAutoWeight = theAutomobile.Weight;



Class Behavior: Methods, Overloading, and Constructors

Methods define the behavior of your class provided--if your class has any.

You can define a class with methods in it or you can create a class with data only. There is no shame in this. You know how to define a method or how to write a signature. The only problem here is what behavior your class should have?. I will address this problem in the second part of this article.

Method overloading is when you define two methods with the same name but with different parameters.


int GetVehicleEfficiency(int weight) //ok

int GetVehicleEfficiency(int weight, string engineType)//ok

int GetVehcileEfficiency(float weight)// Great

float GetVehicleEfficiency(int weight) // Not OK you cannot change return type. This will confuses the compiler

This sounds like a great feature to have but should you use it. I would say that you should avoid it--Why?

It always confuses me if I declare two methods with a different number of parameters but if you keep the no of parameters same and change the type of parameter then method overloading is of great use.

Hence always avoid confusion while programming because it will make you drag you.


A constructor is a specialized method with the same name as the class and every class that you create has one default constructor with no parameters.


Class MotorVehicle{

String engineType;

// rest of the class code..

// The default contstructor
MotorVehicle aVehicle = new MotorVehicle();

You can create an object in many ways by overloading the constructor:


Class MotorVehicle{

String engineType;


engineType =default;

MotorVehicle(String anEngineType)


this.engineType= anEngineType;



// creating objects

MotorVehicle aVehicle = new MotorVehicle();

MotorVehicle aVehicle = new MotorVehicle("Diesel Engine");


Also, avoid using many constructors approach because this will also create the confusion and ultimately drag you.

You can see that there are features that are available to you but there are people who are ahead of the game like uncle Bob and Martin Fowler. They teach us some principles and patterns which tells not to use some features and use other features in a certain manner.


These patterns and principles given by seniors are a great way to avoid mistakes. You have to learn them if you want to be in the league of elite developers.

Another such suggestion (which also restrict you to use some features ) is to avoid setters methods or avoid changing the state of an object and this leads to another advanced level concept for professional and that is immutable objects.

Immutable Objects: Advance Tool for Professionals

An immutable object is an object whose state cannot be changed after it is created. With immutable objects, if you want an object with the different state then you will have to destroy the old object and create the new object with the desired state.

How can you create an immutable object?

Don’t let anyone change the state of an object and one way to this is: don’t provide any setter method for the object.

Making all data member private i.e only accessible within the class.

There are other sophisticated methods to create immutable objects such as factory method to create objects but for now, keep it simple.

Example of immutable object:

One example of an immutable object is String object in C#.

String data="Work";


Console.Writeline(data); // This will print: "Work"

String anotherData = data.toUpper();
Console.Writeline(anotherData);  //  This will print:"WORK"
Console.Writeline(data); // This will print the original: "Work"

As you can see that when method ToUpperCase() is called, it does not change the underlying string. But it creates another object with the modified string as shown in the second line. Therefore strings in C# (even in Java) are immutable objects.

But why use the immutable object?

Why I choose the discussion of immutable objects here. I can easily flash around a few definitions of objects and classes and move on but this article is written for people who are ahead of college kids and have a certain level of programming experience and they want to move ahead.

When you are in the league of elite developers you have to faced the challenges of multi-threaded programming and I have seen so many experienced developers failing on the battleground of multithreading.

Therefore, the immutable object is a tool that you can use in multi-threaded programming. Because immutable objects are thread-safe. How to use them in multi-threading is out of the scope of this article but add this tool in your toolbox so that when you work on a multi-threaded application then you can pick that tool and use it.


People called it information hiding even some people go ahead and called that it is good for security. But both of these terms as I recall from my experience are misleading.

From information hiding, it seems like an object is not going to share data with other objects but this is not the case. An object should share data and/or responsibilities and without sharing there is no use of an object. Let me share a personal story.

If you have worked in a software developer where demos and trade shows are important for marketing you know that demos are important. On such demo day, there was an urgent requirement to change the display of a software and I was asked to make the change. There were other engineers involved in that product.

The change was small. I have to add two fields to the display panel. I create another class and since both of these parameters were related therefore I put them in a single class and use the object of that class.

I did this to make the user interface code to look cleaner. Because in such a stressed situation (the night before the demo) you cannot afford to make tiny mistakes. The code worked and one of the engineers praises me in such a way that I still remember that after so many years. He told me that “Wow you created a new variable and use that!”

See, he is telling that an object equals variable. First of all, I don’t want my readers to be like that i.e treating an object like a variable. Beside that this story depicts the concept of encapsulation.

You merge two or more data and/or functions into a single entity(the variable). This is called encapsulation.

Hence the concept of encapsulation is more towards modularity then security or hiding something. It is more towards making an object/class represent a single modular concept. Hence use it in that way.

Naming: So that you can Read Your Code after 6 Months

It is a good place to talk about naming when we are discussing the internals of the class and objects. As a professional developer how you should properly name your class, member variables, and member functions.

As a rule, you should name your function and variables in such a manner that there are no needs for comments. How?

As a professional you know that most of your time is spent maintaining the code that you have written. This includes fixing bugs, making improvements, adding features and using your code written for one project to other projects.

Therefore it is important for you to write code that is easy to understand for you or for any other developer. One way to achieve this is through comments. You can write comments to elaborate your code.

Another better approach is to name your variables and function in such a way that there is no need for comment.

For variables use elaborative names. Never use short names e.g. You can only use short names(i,j,k) in the loops e.g.

In order to do that you will have to make your function shorter.

If you have a large function currently then divide it into multiple small functions. Each function can contain only 3-5 lines. It looks like an exaggeration but you get the idea. Small enough functions whose purpose can be defined in their name.


// Descriptive and meaningful methods and variable and class names 

int GetProcessedData();
void TransformAllPositions();

int endingFrameLocation;
int firstPositionInDatabase;

class BodySearcher {}
class FileParser {}

In this way your class name, variable names and function names will convey the reader of your code about the minute detail and will help him understand the code better.

For now, this is enough for inside the class concepts. Let’s move to concepts outside the boundaries of class(Part 2).

Too Long Didn't Read(TLDR) Summary

  1. Object-oriented programming is a development methodology.
  2. Behave with class like a tool to capture your concepts
  3. Objects are the real thing and always think that how your objects are going to live in memory. This will make your life easy
  4. Treat static as global variables. Avoid them or use them consciously
  5. Give universal access to class variables using accessors.  Make your code re-usable.
  6. Methods signatures --how to avoid confusion by avoiding method overloading
  7. Use Immutable objects generally and especially with multi-threading
  8. A different approach to encapsulation
  9. Write code for humans first and then leave the machine side to the compiler.


To learn more about object-oriented programming and object-oriented design click here where I synthesize learnings from the real-world and real-life project.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior)
Pakistan Pakistan
If you want to learn more about object-oriented design, programming using real-life and real-world examples then you should visit:

You will know what it takes to be great at programming and what lies ahead in your career: Is that money, authority or fame?

My name is Muhammad Umair and I write about programming, programmers, and object-oriented design and how you can optimize your programming skills to advance your programming career.

You may also be interested in...


Comments and Discussions

AnswerMessage Closed Pin
18-Dec-17 23:16
memberMember 1358425018-Dec-17 23:16 
QuestionPeople who are old and rigid? Remove that... Pin
Mike Barthold12-Dec-17 19:07
professionalMike Barthold12-Dec-17 19:07 
AnswerRe: People who are old and rigid? Remove that... Pin
Muhammad Umair At CodeProject13-Dec-17 3:57
memberMuhammad Umair At CodeProject13-Dec-17 3:57 
GeneralRe: People who are old and rigid? Remove that... Pin
Paulo Zemek14-Dec-17 11:56
professionalPaulo Zemek14-Dec-17 11:56 
QuestionLearn more about Association, Aggregation, and Composition Pin
Gerd Wagner5-Dec-17 8:53
professionalGerd Wagner5-Dec-17 8:53 
QuestionSuggestion Pin
David O'Neil5-Dec-17 6:58
professionalDavid O'Neil5-Dec-17 6:58 
AnswerRe: Suggestion Pin
Muhammad Umair At CodeProject5-Dec-17 14:42
memberMuhammad Umair At CodeProject5-Dec-17 14:42 
QuestionMessage Closed Pin
4-Dec-17 23:33
membertarun _sharma4-Dec-17 23:33 
GeneralMy vote of 2 Pin
Pete O'Hanlon4-Dec-17 20:56
protectorPete O'Hanlon4-Dec-17 20:56 
GeneralRe: My vote of 2 Pin
Muhammad Umair At CodeProject5-Dec-17 2:32
memberMuhammad Umair At CodeProject5-Dec-17 2:32 
General[My vote of 1] My vote is 0.1 Pin
hrides4-Dec-17 18:17
memberhrides4-Dec-17 18:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180417.1 | Last Updated 13 Dec 2017
Article Copyright 2017 by omeecode
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid