which come first class or object in object oriented languages ?
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.
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.
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.
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.
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.
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.
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.
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.
The short answer is that objects come first.
The long answer is well - long :)
- These languages are called object oriented, for reason.
- Every OO language employees the mantra everything is an object. This includes classes.
- There are even languages which although not OO, support OO programming (like Erlang)
- We can think of a classes really in different terms:
- In most class bases based languages the main reason for using classes is supporting Nominative typing. That is the possibility to distinct to objects by their "type" (for instance Fruit and Star).
- Classes commonly plays naming role. I mean that some OO languages (like Java) does not have explicit notion of environment, it is played by all classes currently in the classpath.
- A class can be also used as a template for creating new objects, and consequently
- A class is commonly an optimization hack - not to duplicate information common to all instances of the class (for instance methods)
I'm sure there are a lot more but this is just for starters :)