Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

80%
+6 −0
Q&A Why object-oriented instead of class-oriented?

Why object-oriented instead of class-oriented? tl;dr Because you can "do OOP" without classes. Long answer A class is one possible way to implement object oriented programming. But it's n...

posted 3y ago by hkotsubo‭  ·  edited 3y ago by hkotsubo‭

Answer
#2: Post edited by user avatar hkotsubo‭ · 2022-01-28T19:29:46Z (almost 3 years ago)
  • > _Why object-oriented instead class-oriented?_
  • # tl;dr
  • Because you can "do OOP" without classes.
  • ---
  • # Long answer
  • A class is **one possible way** to implement object oriented programming. But it's not the only one.
  • OOP is a programming paradigm: a particular "style"/way of designing programs. First of all, let's remind that [there's no single, unique, upon-agreed, free-of-controversies, canonical definition for OOP](http://wiki.c2.com/?NobodyAgreesOnWhatOoIs). But most people "usually (tend to) <sup><sub>_kinda_</sub></sup> agree" on three basic pillars:
  • 1. encapsulation: don't expose an object's internal details to other objects.
  • 2. inheritance: one object can acquire properties and methods of another object.
  • 3. polymorphism: the ability to occurr in several different forms.
  • As I said, there's not a consensus about the correct definition. Some add a fourth pillar ("abstraction"), and we could debate the definition for hours, but that's beside the point. In case you're interested, [there's already a post here](https://software.codidact.com/posts/282832) with a more detailed discussion.
  • ---
  • Anyway, you can achieve all those things (encapsulation, polymorphism, etc) without using classes.
  • For example, JavaScript uses [prototypes](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object_prototypes) to implement inheritance.
  • [JavaScript has a way to define classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) using the `class` keyword, but that's just a syntax sugar, because in the end they're all "special" functions:
  • ```javascript
  • class Rectangle {
  • constructor(height, width) {
  • this.height = height;
  • this.width = width;
  • }
  • }
  • console.log(typeof Rectangle); // function
  • ```
  • You can also achieve an object-oriented design with languages that have no classes, such as C - [see an example here](https://software.codidact.com/posts/283888).
  • ---
  • > _an object is an instance of a class_.
  • In a general way, an object is something (a structure, a container, etc) that contains data (fields/attributes/properties) and "behaviour" (usually in the form of methods, that manipulate the data).
  • <sup>[In a _more_ general way](https://en.wikipedia.org/wiki/Object_(computer_science)), an object can be a variable, data structure, function/method, etc. Basically, any region of memory that has a value and can be accessed by some identifier.</sup>
  • For languages that have classes, though, an object is usually defined as an instance of a class.
  • But different languages can have different definitions. For example, [MDN defines a JavaScript object](https://developer.mozilla.org/en-US/docs/Glossary/Object) as "_a collection of properties_". And you can create an object without using classes (considering that the language doesn't actually have classes, I mean "_you can create an object without using the `class` keyword_"):
  • ```javascript
  • var obj = {
  • somefield: 1,
  • somemethod: function () {
  • console.log(this.somefield);
  • }
  • };
  • obj.somemethod(); // 1
  • ```
  • Python, on the other hand, [defines an object](https://docs.python.org/3/reference/datamodel.html#objects-values-and-types) as "_abstraction for data_", which means that all data is represented by objects and relations between those (even a single number as `1` is also an object).
  • C11, [section 3.15](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf), defines object as "*region of data storage in the execution environment, the contents of which can represent values*".
  • Anyway, some languages define an object as an instance of a class, but the actual definition is way broader and it can vary according to the language. It's not something restricted to classes only.
  • A class is just a mechanism that some languages provide to achieve OOP goals (encapsulation, polymorphism, inheritance, etc). In the languages that have classes, I recognize that it makes things easier, IMO.
  • But it doesn't mean they're the only way to do it, you can do OOP without classes. That's why the paradigm isn't called "class-oriented programming".
  • > _Why object-oriented instead of class-oriented?_
  • # tl;dr
  • Because you can "do OOP" without classes.
  • ---
  • # Long answer
  • A class is **one possible way** to implement object oriented programming. But it's not the only one.
  • OOP is a programming paradigm: a particular "style"/way of designing programs. First of all, let's remind that [there's no single, unique, upon-agreed, free-of-controversies, canonical definition for OOP](http://wiki.c2.com/?NobodyAgreesOnWhatOoIs). But most people "usually (tend to) <sup><sub>_kinda_</sub></sup> agree" on three basic pillars:
  • 1. encapsulation: don't expose an object's internal details to other objects.
  • 2. inheritance: one object can acquire properties and methods of another object.
  • 3. polymorphism: the ability to occurr in several different forms.
  • As I said, there's not a consensus about the correct definition. Some add a fourth pillar ("abstraction"), and we could debate the definition for hours, but that's beside the point. In case you're interested, [there's already a post here](https://software.codidact.com/posts/282832) with a more detailed discussion.
  • ---
  • Anyway, you can achieve all those things (encapsulation, polymorphism, etc) without using classes.
  • For example, JavaScript uses [prototypes](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object_prototypes) to implement inheritance.
  • [JavaScript has a way to define classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) using the `class` keyword, but that's just a syntax sugar, because in the end they're all "special" functions:
  • ```javascript
  • class Rectangle {
  • constructor(height, width) {
  • this.height = height;
  • this.width = width;
  • }
  • }
  • console.log(typeof Rectangle); // function
  • ```
  • You can also achieve an object-oriented design with languages that have no classes, such as C - [see an example here](https://software.codidact.com/posts/283888).
  • ---
  • > _an object is an instance of a class_.
  • In a general way, an object is something (a structure, a container, etc) that contains data (fields/attributes/properties) and "behaviour" (usually in the form of methods, that manipulate the data).
  • <sup>[In a _more_ general way](https://en.wikipedia.org/wiki/Object_(computer_science)), an object can be a variable, data structure, function/method, etc. Basically, any region of memory that has a value and can be accessed by some identifier.</sup>
  • For languages that have classes, though, an object is usually defined as an instance of a class.
  • But different languages can have different definitions. For example, [MDN defines a JavaScript object](https://developer.mozilla.org/en-US/docs/Glossary/Object) as "_a collection of properties_". And you can create an object without using classes (considering that the language doesn't actually have classes, I mean "_you can create an object without using the `class` keyword_"):
  • ```javascript
  • var obj = {
  • somefield: 1,
  • somemethod: function () {
  • console.log(this.somefield);
  • }
  • };
  • obj.somemethod(); // 1
  • ```
  • Python, on the other hand, [defines an object](https://docs.python.org/3/reference/datamodel.html#objects-values-and-types) as "_abstraction for data_", which means that all data is represented by objects and relations between those (even a single number as `1` is also an object).
  • C11, [section 3.15](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf), defines object as "*region of data storage in the execution environment, the contents of which can represent values*".
  • Anyway, some languages define an object as an instance of a class, but the actual definition is way broader and it can vary according to the language. It's not something restricted to classes only.
  • A class is just a mechanism that some languages provide to achieve OOP goals (encapsulation, polymorphism, inheritance, etc). In the languages that have classes, I recognize that it makes things easier, IMO.
  • But it doesn't mean they're the only way to do it, you can do OOP without classes. That's why the paradigm isn't called "class-oriented programming".
#1: Initial revision by user avatar hkotsubo‭ · 2022-01-28T13:30:11Z (almost 3 years ago)
> _Why object-oriented instead class-oriented?_

# tl;dr

Because you can "do OOP" without classes.

---

# Long answer

A class is **one possible way** to implement object oriented programming. But it's not the only one.

OOP is a programming paradigm: a particular "style"/way of designing programs. First of all, let's remind that [there's no single, unique, upon-agreed, free-of-controversies, canonical definition for OOP](http://wiki.c2.com/?NobodyAgreesOnWhatOoIs). But most people "usually (tend to) <sup><sub>_kinda_</sub></sup> agree" on three basic pillars:

1. encapsulation: don't expose an object's internal details to other objects.
2. inheritance: one object can acquire properties and methods of another object.
3. polymorphism: the ability to occurr in several different forms.

As I said, there's not a consensus about the correct definition. Some add a fourth pillar ("abstraction"), and we could debate the definition for hours, but that's beside the point. In case you're interested, [there's already a post here](https://software.codidact.com/posts/282832) with a more detailed discussion.

---

Anyway, you can achieve all those things (encapsulation, polymorphism, etc) without using classes.

For example, JavaScript uses [prototypes](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object_prototypes) to implement inheritance.

[JavaScript has a way to define classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) using the `class` keyword, but that's just a syntax sugar, because in the end they're all "special" functions:

```javascript
class Rectangle {
  constructor(height, width) {
    this.height = height;
    this.width = width;
  }
}
console.log(typeof Rectangle); // function
```

You can also achieve an object-oriented design with languages that have no classes, such as C - [see an example here](https://software.codidact.com/posts/283888).

---

> _an object is an instance of a class_.

In a general way, an object is something (a structure, a container, etc) that contains data (fields/attributes/properties) and "behaviour" (usually in the form of methods, that manipulate the data).

<sup>[In a _more_ general way](https://en.wikipedia.org/wiki/Object_(computer_science)), an object can be a variable, data structure, function/method, etc. Basically, any region of memory that has a value and can be accessed by some identifier.</sup>

For languages that have classes, though, an object is usually defined as an instance of a class.

But different languages can have different definitions. For example, [MDN defines a JavaScript object](https://developer.mozilla.org/en-US/docs/Glossary/Object) as "_a collection of properties_". And you can create an object without using classes (considering that the language doesn't actually have classes, I mean "_you can create an object without using the `class` keyword_"):

```javascript
var obj = {
    somefield: 1,
    somemethod: function () {
        console.log(this.somefield);
    }
};

obj.somemethod(); // 1
```

Python, on the other hand, [defines an object](https://docs.python.org/3/reference/datamodel.html#objects-values-and-types) as "_abstraction for data_", which means that all data is represented by objects and relations between those (even a single number as `1` is also an object).

C11, [section 3.15](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf), defines object as "*region of data storage in the execution environment, the contents of which can represent values*".

Anyway, some languages define an object as an instance of a class, but the actual definition is way broader and it can vary according to the language. It's not something restricted to classes only.

A class is just a mechanism that some languages provide to achieve OOP goals (encapsulation, polymorphism, inheritance, etc). In the languages that have classes, I recognize that it makes things easier, IMO.

But it doesn't mean they're the only way to do it, you can do OOP without classes. That's why the paradigm isn't called "class-oriented programming".