Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

types in object oriented programming

Tags:

java

c++

c

oop

I'm confused about why classes are considered data types.

I understand that part of them is "data", and the other part is the methods. Why are they called data types?

Procedures in procedural programming languages, like C, hold one or more fundamental data types, sometimes. But they are not called data types.

like image 273
wajed Avatar asked Jun 01 '11 06:06

wajed


People also ask

How many types of object-oriented are there?

The four principles of object-oriented programming are encapsulation, abstraction, inheritance, and polymorphism.

What are the 5 object-oriented programming concepts?

When completing an object-oriented design, there are five basic concepts to understand: classes/objects, encapsulation/data hiding, inheritance, polymorphism, and interfaces/methods.

What are the three object-oriented programming?

There are three major pillars on which object-oriented programming relies: encapsulation, inheritance, and polymorphism.


1 Answers

Given the definition at Wikipedia:

[...] a data type (or datatype) is a classification identifying one of various types of data, such as floating-point, integer, or Boolean, that determines the possible values for that type; the operations that can be done on values of that type; and the way values of that type can be stored.

I believe classes fit the definition quite well, while procedures in procedural programming like C don't fit at all.

Classes represent a set of possible values (objects) and defines the possible operations that can be done on the values of this type. It also makes it clear how to represent objects of the class in memory.

Procedures in C however does not identify a set of possible values and it wouldn't make sense to say that there are definitions stating what operations can be performed on procedures.

Perhaps your confusion stems from some text on functional programming where a procedure (or function) is treated as a first class value which has a specific type.

like image 181
aioobe Avatar answered Nov 14 '22 23:11

aioobe