3

Possible Duplicate:
Why “class” for class in Java?

I was thinking about type classes in Haskell, which allow you to separate types into different groups based on the operations you can perform on them. But why are classes called classes in C++? What were they originally meant to classify?

Community
  • 1
  • 1
gct
  • 14,100
  • 15
  • 68
  • 107

6 Answers6

10

Because they were called "classes" in Simula. Sources indicate that Simula was influenced by this proposal for "record classes" (i.e. structured data with associated type information) in Algol. Mostly every other language derived its OO terminology (directly or indirectly) from Simula.

hobbs
  • 223,387
  • 19
  • 210
  • 288
5

to categorize a real world entity (objects) .

birubisht
  • 890
  • 8
  • 16
  • 1
    Not sure about the "real world" part. – Thilo Sep 11 '12 at 03:47
  • everything around you can be thought as an object of a particular class or you can say entities which have some common property and behavior can be kept in particular class to indicate them by a common group. – birubisht Sep 11 '12 at 03:53
  • Yes, but mathematician and computer scientists also like to categorize and classify abstract non-real-word things and concepts. – Thilo Sep 11 '12 at 03:56
  • @Thilo: I understand that is just a nitpick and that you do understand what the answer means. Call them *domain entities* if you wish, rather than *real world entities*, but at any rate it is a taxonomy of objects in the program. – David Rodríguez - dribeas Sep 11 '12 at 03:58
  • Nit-picking aside, I do take umbrage at the idea that OOP has much to do with real-world objects. Mentioning them makes this answer worse than Brian's or Greg's. – Thilo Sep 11 '12 at 04:02
3

Classes in C++ are meant to classify objects.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
3

They classify objects, hence the name :)

Brian Kelly
  • 19,067
  • 4
  • 53
  • 55
2

Actually the uncommon use is the one in haskell. In most OO languages class is used to refer to a type that defines the behavior of a class of objects. For example, Car is a class of objects of which there are many instances, my car, your car, someone elses car. In Haskell, the term is used in a metalanguage level to refer to classes of types, rather than classes of objects.

David Rodríguez - dribeas
  • 204,818
  • 23
  • 294
  • 489
0

In object oriented programming, you have objects which have state and support some operations. The state and stuff is wildly different for some different objects (e.g. an object representing a bank account in a financial program, vs an object representing a car in a racing simulator). So we can't treat all objects the same way.

A class represents a bunch of objects which work similarly. If you know that an object belongs to some class, then you know some kinds of things you can do with it. Objects representing a bank account might support operations like deposit, withdraw, getBalance, getAccountHolder.

Talking about "the class of objects which support the deposit, withdraw, getBalance, and getAccountHolder operations", or "the class of objects which support the accelerate, and getSpeed, and steer methods" is just normal use of the word "class" (and is related to "classify", which basically just means "to put into classes"; the word "class" as in a group of students is quite different).

Obviously, you pretty quickly want to name particular classes, so that you can just say BankAccount or RacingCar, rather than "the class of objects which support ...".

So a class is just that; a "thing" that defines what is common to the objects which are instances of the class.

Ben
  • 68,572
  • 20
  • 126
  • 174