Object Oriented Programming Paradigms

Introduction

  • When creating computer programs, we conceptualize a solution to a problem, figuring out what data is needed and the steps to solve the problem with that data.
  • There are different ways to organize and conceptualize solutions, leading to different programming paradigms or philosophies.
  • These paradigms have emerged as programs have tackled bigger and bigger problems.

Imperative and Procedural Programming

  • Up until now, we have used imperative and procedural programming a lot.
  • This paradigm involves step-by-step instructions to achieve a goal.
  • It uses basic programming commands.
  • Data, files, and user input may be used, but input is usually requested when needed.
  • The program is in control, incrementally changing its state through small steps to arrive at the solution.
  • Food recipes and furniture assembling descriptions are real-world examples.
  • You can get far using this approach.

Event Driven Programming

  • We've also seen a little bit of event-driven programming, especially with graphical user interfaces (GUIs).
  • Event-driven programming involves creating code that reacts to user interaction, such as button clicks and mouse movements.
  • There's a main loop in the background waiting for events to happen.
  • When an event occurs, the loop calls the code that has registered an interest in that event.
  • This interaction changes the world incrementally, such as drawing on the screen or changing data.
  • When creating a program using this event driven paradigm we still have data, we still have these snippets of imperative or procedural programs, step by step instructions to achieve something. So there's actually not that much of difference.

The Issue of Complexity

  • As problems get bigger, code in imperative and event-driven paradigms tends to become increasingly complex.
  • The interaction between data and code becomes hard to grasp for developers.
  • It's easy to make mistakes, with code interacting with data in unexpected ways.
  • Object orientation aims to address this by providing a way of structuring the data better with interactions that needs to happen, which would be able to limit that.

Object Orientation

  • Object orientation involves developing a world of data and interaction within objects that interact with each other.
  • Objects are self-contained entities, encapsulating data and the operations on that data.
  • This encapsulation helps to know where and how things are working with that data and what you want it to achieve.
  • Information is hidden, and objects interact with each other through methods, providing an interface for interaction.
  • Classes are recipes to create objects.
  • Creating an object is instantiating or creating an instance of an object of that class.
  • The events are calling these methods on objects.
  • Object orientation still uses event-driven and imperative/procedural paradigms, but packages them strategically to avoid problems as programs grow.

Classes, Attributes, and Methods

  • A class has attributes (also called fields) and methods.
  • Methods are the behaviors of the objects of this class.
  • Objects talk to each other through methods, keeping attributes safe and changeable only through these methods.
  • An object is a collection of data wrapped together with a collection of operations that you can work with that data.
  • Classes have fields, which are variables living within objects.
  • Methods are the actions that can happen on that data.
  • Constructors in the class are recipes to create an object, defining what needs to be set up for an object to exist, the birth of an object, so to speak.
  • Constants can also exist within an object.

Examples of Objects

  • Examples of objects include string, butterfly, animals, scanners, and print stream.
  • Now it's time to start describing our own.
  • The next videos will talk about the various aspects of an object, a class and object, and how they relate, and how we use it.