Reputation: 1
which come first class or object in object oriented languages ?
Upvotes: 0
Views: 388
Reputation: 21
The short answer is that objects come first.
The long answer is well - long :)
I'm sure there are a lot more but this is just for starters :)
Upvotes: 0
Reputation: 15431
A class is like the total ingredients and procedure for making a soup, while an object is the soup it self.
The ingredients can be objects its own right, so the class definition for an ingredient would be for example: The name of the ingredient, the color, the size, and what you can do with the ingredient.
Programming Example:
class You {
string name;
string height;
string complexion;
void run() {
}
void swim() {
}
...
}
I hope this helps.
Upvotes: 0
Reputation: 13059
An object is an instantiation of a class. The class comes first.
The class represents a blueprint or template of an object. It is the exact layout, which describes how to build the object. In the classical OO sense, the class is required first in order to build the object.
It is a philosophical question whether, in real-life, the top-down approach (class first, then object) or bottom-up approach (object first, then class abstraction) is better.
Lastly, apparently someone can come up with a language that employs OO concepts without classes, but IMO that is not really what the question was about.
Upvotes: 2
Reputation: 7781
But still in real life we have things like particles and atoms. We described their details millions of years later - they existed fine without any 'class' or definition how to make them.
Class is a blue-print of the object, it is build of base forms like integers, strings etc. So in theory object 'typeof(object)' is the most base form and it does not require any class.
Therefore I would say object was first, unless someone will present me a class definition of object.
Object as 'idea' definitely came first, we created classes to describe properties of each object.
Upvotes: 0
Reputation: 4892
In both Java and C++, class comes first. There can be no object without a class.
A class is like a blueprint. The object the car. With one blueprints, many cars can be built. With one class, many objects can be instantiated.
This in contrast to prototype-based OOP languages, like JavaScript. There you create a generic object, and turn give it its features separately.
Upvotes: 0
Reputation: 6983
It's a lot easier to come up with a good design if you think in terms of the objects first and then work out what classes you need to make them.
Not all OOP languages have classes - and you don't need them.
In Ruby for example you can define new methods on an object and just clone the objects themselves - or you can do traditional design and define new classes.
In Self you don't define classes at all. Rather you add methods to a "prototypical example object" and clone copies of it when you need new "instances".
Lots of people like to start designing OO systems with class diagrams but unfortunately, that's a symptom of SQL thinking rather than OO thinking. Above all else - objects do things.
Upvotes: 2
Reputation: 3922
According to wikipedia the first language with explicit feature support for OOP was Simula which included the concept of a class. More recently there have been OOP langugages which use prototypes rather than classes such as javascript.
Upvotes: 0
Reputation: 1949
I would say its Class. Imagine a a human body template without life and attributes.And when you give the above said blood and heart its beautiful and live. class is just a template and object is one thing with all the properties and an individual.
Upvotes: 0
Reputation: 308763
Think of a class as a cookie cutter and the object as the cookies. Classes are specifications; objects are realizations of those specifications in memory.
Classes come first. Can't have an object without a class.
Upvotes: 0