Skip to content

Moving to OO from Procedural

Estimated time to read: 2 minutes

Moving from COBOL or C, Object Oriented programming can seem mystifying.

Procedural Design

In a procedural language, there is a clearly defined starting point for the program. We find that point and work our way down to the end, like reading a book. Everything happens in order.

In procedural design, flow charts and pseudo-code is used to describe what the code must do.

Object-Oriented Design

Object Oriented programs also have clearly defined starting points. If using a framework, it may be highly likely that you are not in control of that starting point. You write handlers which deal with the requests of data, but you are not the one fully in control.

Services can handle many different requests, a framework traditionally handles all of the incoming requests, decoding, etc, we are not required to handle this as it is done for us. An object ideally does not expose any of its data, only its public interface, this is how we converse with it.

We won't start our design there though. Instead, we'll define all the different things the system needs to do and design them individually. We are effectively writing extensions to a larger framework that we can hook in to.

In Object-Oriented programming, we start with a high-level view of the application and keep refining the design to eventually implement it using encapsulation.

Collaboration and Encapsulation

Object-Oriented programs are often referred to as systems or applications instead of programs.

Object-Oriented systems are often made up of dozens or even hundreds of separate source code files:

  • Each of these files will be relatively small and will serve a specific purpose (encapsulation).
  • The 'application' is crated by these small files working together to accomplish specific tasks (collaboration)

Single Responsibility Principle (SRP)

In Java, a file represents a single public class, it does one job. You cannot have more than one public class in a file and you cannot spread a public class across more than one, so there is an isomorphism there to a large extent.