Sunday, January 8, 2023
By: Matthew Doucette
ChatGPT is amazing.
I used it to extend the four principles of object oriented programming (OOP). Could it come up with a fifth prinicple that a professional programmer would agree with?
First let's use ChatGPT to explain the original four priniciples. As a bonus, we will pay attention to the distinction between encapsulation and abstraction, which are often prinicples not well understood and mistaken for one-another:
What are the four principles of object oriented programming?
The four principles of object-oriented programming are:
Encapsulation: Encapsulation is the process of bundling data and methods that operate on that data within a single unit, or object. This is intended to reduce complexity and increase modularity by allowing developers to think about each object in isolation.
Abstraction: Abstraction is the process of exposing only the relevant and essential characteristics and behaviors of an object, while hiding its implementation details. This is intended to help developers focus on what an object does, rather than how it does it.
Inheritance: Inheritance is the process of creating a new class that is a modified version of an existing class. The new class is called the subclass, and the existing class is the superclass. The subclass inherits attributes and behaviors from the superclass, and can also have additional attributes and behaviors of its own.
Polymorphism: Polymorphism is the ability of a class to take on multiple forms. This can be achieved in a number of ways, such as through inheritance, where a subclass can override or extend the attributes and behaviors of its superclass, or through the use of interfaces, which allow a class to implement a set of behaviors that are defined by the interface.
ChatGPT appears to understand the four principles of OOP and gives a great breakdown of encapsulation vs. abstraction. Notice the explanation is more than technical, where a technical-only explanation often leads to the misunderstandings, and connects to how the developer should think about and use the principles. ChatGPT writes responses that people understand, above and beyond just technical accuracy. I am amazed by this.
Now, let's see if ChatGPT can come up with a fifth prinicples of object oriented programming:
What would a fifth principle be if you had to come up with one?
There is no widely accepted "fifth principle" of object-oriented programming. However, if I had to come up with one, it might be "modularity": the idea that code should be organized into independent, interchangeable units that can be easily reused and combined in different contexts. Modularity can be achieved through the use of encapsulation, abstraction, and other techniques, and it is often seen as an important factor in creating maintainable, scalable software.
What an excellent fifth principle! ChatGPT appears to fully understand the purpose and reasoning behind object oriented programming.
What is ChatGPT?
ChatGPT is a language model trained to have full conversations, that allows for followup questions, admission of mistakes, and ability to challenge incorrect premises. Just think about that last one. If you feed it a loaded question based on a false premise, it will call you out on it.
Statistics / References:
For reference purposes, these chats took place on Saturday, January 7th, 2023 using "ChatGTP Dec 15 Version."
That is all.
About the Author: I am Matthew Doucette of Xona Games, an award-winning indie game studio that I founded with my twin brother. We make intensified arcade-style retro games. Our business, our games, our technology, and we as competitive gamers have won prestigious awards and received worldwide press. Our business has won $190,000 in contests. Our games have ranked from #1 in Canada to #1 in Japan, have become #1 best sellers in multiple countries, have won game contests, and have held 3 of the top 5 rated spots in Japan of all Xbox LIVE indie games. Our game engines have been awarded for technical excellence. And we, the developers, have placed #1 in competitive gaming competitions -- relating to the games we make. Read about our story, our awards, our games, and view our blog.