types in object oriented programming

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.

Answer

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.

Leave a Reply

Your email address will not be published. Required fields are marked *