Is there any relationship between the term object as an output of compiling/assembling (like:Shared Object files) and object as in OOP languages (an instance of a class). Why both are called object? What is the term object in computer science and how it can be used?
No ... there is no relationship between these things. The word object is overloaded in every aspect of English and software is not an exception.
The object file (.o file) is called this only because that is what it has been called for 40+ years (See Here); well before the idea of object oriented programming (OOP). OOP is called as such because it is a programming style which groups ideas/functionalities into objects (See Here).
Related
I've recently stumbled upon interesting question (or maybe only author's mistake) and I've started to question myself. After some research I have to say I am not 100% sure of my answer, so I would like to ask if my thinking is correct. The question is:
Describe object oriented programming paradigms
I was first thinking that this is polymorphism, inheritance, encapsulation, abstraction. But why there is multiple form? As I understood my answer is description of paradigm (single) not paradigms (plural). Did I miss something, or this is correct answer?
Basing my argument on definition of paradigm which is generally a pattern of doing something. The paradigms would be:
Abstraction
Encapsulation
Polymorphism
Inheritance.
You might want to check out what Alan Kay has to say about this: http://c2.com/cgi/wiki?AlanKaysDefinitionOfObjectOriented
The necessary excerpts from the link:
This definition is derived from early versions of Smalltalk (Smalltalk-72?), and rules 5 and 6 clearly show Smalltalk's Lisp heritage. Kay remarked as such, noting that rules 4-6 would mutate as Smalltalk developed.
EverythingIsAnObject.
Objects communicate by sending and receiving messages (in terms of objects).
Objects have their own memory (in terms of objects).
Every object is an instance of a class (which must be an object).
The class holds the shared behavior for its instances (in the form of objects in a program list)
To eval a program list, control is passed to the first object and the remainder is treated as its message.
"Alan Kay, considered by some to be the father of object-oriented programming, identified the following characteristics as fundamental to OOP:"
EverythingIsAnObject.
Communication is performed by objects communicating with each other, requesting that objects perform actions. Objects communicate by sending and receiving messages. A message is a request for action, bundled with whatever objects may be necessary to complete the task.
Objects have their own memory, which consists of other objects.
Every object is an instance of a class. A class simply represents a grouping of similar objects, such as integers or lists.
The class is the repository for behavior associated with an object. That is, all objects that are instances of the same class can perform the same actions.
So far, similar to 1-5 above. Rule 6 is different. The reference to lists is removed, instead we have:
Classes are organized into a singly-rooted tree structure, called the inheritance hierarchy. Memory and behavior associated with instances of a class are available to any class associated with a descendent in this tree structure.
It depends on the viewing angle, better to say on the granularity, or what do you want to compare or emphasize.
Object oriented programming is one programming paradigm among others. But then there are different categories of object oriented programming. It makes sense to call the plurality of them object oriented programming paradigms.
See https://en.wikipedia.org/wiki/Object-oriented_programming for a beautiful list of programming paradigms.
OOP has its roots in the late 1960s and early 1970s, and it was formally introduced in the late 1980s. The main proponents of OOP were Alan Kay, Bertrand Meyer, and Grady Booch.
The idea behind OOP is to represent real-world objects and their behavior in a computer program. This allows developers to write software that is more intuitive and easier to understand, as well as reuse code by creating objects that can be used in multiple applications.
Object-Oriented Programming (OOP) is a programming paradigm based on the concept of objects, which can contain data and behavior. In OOP, objects interact with each other by sending messages, and objects can be grouped into classes, which define their shared behavior and data.
OOP has evolved over time, and its use has become widespread in the software industry. Today, several programming languages support OOP, including PHP, Java, Python, C++, Ruby, and more.
You can read further in this post: What is OOP - Object Oriented Programming
Is class an object in object oriented language? How are Class methods accessed by just name of the class.method name? (internal working). Is this same as a object.method?
And If the Class is same as object (belong to object class which is super class of every thing in OO) and we instantiate it (make object of it), can we make instance of an instance of an class other than Object class.
(Mainly interested in the theoretical perspective even if practically not required ever)
Well, it depends on the language that you are using; in pure OO languages where everything is an object (e.g. Smalltalk) classes are no exception and are objects too. In other languages where classes are not considered as first class citizens they are just special language constructs or primitive types. From now on I'll use Smalltalk as a target language, due to its reflection support and homogeneous style.
How Class methods are accessed by just name of the class.method name?
(internal working). Is this same as as object.method?
Since classes are objects, they are in turn instances of a class (a metaclass). Thus, sending a message to the class is just sending a message to an object whose role is to represent how classes behave. There is a lot of literature out there, you can take a look for example here and here for some introduction.
And If the Class is same as object (belong to object class which is
super class of every thing in OO) and we instantiate it (make object
of it), can we make instance of an instance of an class other than
Object class.
I'm not sure I follow you here, but just for clarification it is not always the case that Object is the superclass of all the classes. The thing is that If you start following the relationships between classes and metaclasses, you may reach a sort of infinite loop. Different languages work this out in different ways and for example, in VisualWorks Smalltalk, Object is a subclass of nil. The thing is that nil is also an object (remember, everything is an object) and it actually represents "nothing". As you may expect, nil is an instance of a class (UndefinedObject) and it also implements some of the class protocol. As a result it can be used to represent a class form where nothing is inherited :).
Finally, I don't know if this answers your question, but yes, you can do many cool things with full reflective capabilities, like creating new classes on the fly or reshaping existing ones. I'll leave you here some documents that you may find interesting regarding this topic:
Metaclasses
Understanding Metaclasses
Debugging Objects
A class isn't an object, you can think of it as a 'blueprint' for an object. It describes the shape and behaviour of that object. Objects are instances of a class.
See here for more information.
Is class a object in object oriented language?
The notion of class is first and foremost theoretical. You can define a thing with "class" semantics even if your language does not support the formal notion of "class" (e.g. Javascript). A class is a template for an object, from which you create instances.
How Class methods are accessed by just name of the class.method name?
I'm not quite sure what you mean. Some languages support "static" or "class" methods, which are methods that are not invoked within the context of an instance of the class. So its not the same as "object.method" which is a normal method on the class where the 'this' (or equivalent) will be the instance on which the method is invoked.
Java (from comments)
For Java, there is a class called Object, and a class called Class. See this. These Java constructs are separate from the notion of Class and Object. The former are implementation details -- they are how the designers constructed the language, the latter are general concepts. So in Java, you can have an instance of an Object, where the instance is an object(the concept) of type Object(the Java construct).
A Basic notion of object means that has been allocated some memory. As devdigital said class is just a blueprint for an object which holds the bare-bone structure and determines how the object will behave when it's it will be instantiated.
Classes are just bodies(without soul) and objects are living bodies(having a soul) that interact with environment or in biological terms respond to external stimuli(public methods and properties) in an analogy to philosophy of life :)
Technically classes are just machine interpretable code residing in memory(not necessary main memory or registers). Objects are code loaded into executable memory(registers/main memory)
I'm currently learning Smalltalk in the Squeak environment and I'm reading "Squeak - A Quick Trip To ObjectLand". I enter the object-oriented paradigm with some prior knowledge from Python and Java and this sentence from the book on page 36 has made me think:
Smalltalk is a class-based implementation of an object-oriented language.
Short sentence but very interesting. In OO all terms like class, object, instance seem to be well-defined and seem to point to the one and only true meaning and you're likely to come across generic sentences like "objects are instances of a class".
But you hear seldom about implementation strategies. What does implementation of the object-oriented concept mean in this case? Are there implementations of OO languages other than classes?
Javascript is a prototype based implementation of an OO language.
Instead of subclassing a class and creating an instance of that new class, you inherit behaviour by cloning a prototype.
As a historical note I should add that while Javascript is probably the most widely used prototype-using language, the first was David Ungar's and Randall Smith's Self language.
There are several implementations of prototypes floating around for Squeak. I haven't used them, so I can't comment on the libraries.
I never saw, but read about Emerald, that is object-oriented but neither class- nor prototype-based but seems to construct objects "one by one" with the help of a special constructor:
However, Emerald objects do not require a Class object for their creation. In most object-based systems, the programmer first specifies a class object that defines the structure and behavior of all its instances. The class object also responds to new invocations to make new instances.
In contrast, an Emerald object is created by executing an object constructor. An object constructor is an Emerald expression that defines the representation, the operations, and the process of an object.
See Andrew Black, Norman Hutchinson, Eric Jul, and Henry Levy: "Object Structure in the Emerald System".
This question already has answers here:
What is the difference between an Instance and an Object?
(25 answers)
Closed 1 year ago.
I just want to know what is the difference between an object and instance with example.
An object is a software bundle of related state and behavior. A class is a blueprint or prototype from which objects are created. An instance is a single and unique unit of a class.
read more :Class vs Object vs Instance
Often the words instance and object are synonyms. Read more about objects
Some languages (e.g. Smalltalk, Common Lisp, and even MELT) are reifying their classes, by having classes instances of meta-classes. In that case, you might say that these class objects are not instance (but it is a matter of terminology and context).
In other languages (e.g. C++) classes are not objects, e.g. because they make only sense at compile-time.
Some object oriented languages (e.g. JavaScript or Self) don't have classes but prototypes.
As has been already mentioned, a class is a blueprint/recipe for creating objects. Hence,
A class is a blueprint for creating objects of that class.
On the reverse side, an object is an instance of that class.
"Object" is a runtime concept, it exists while running. That is when, for example in Java,
when the program execution reaches a statement where is says
ClassA objA = new ClassA();
it is then that an object of that class is created, or instantiated. In the above code, objA is an instance of ClassA.
Suppose you have an imaginary type system for an imaginary scripting language which is written in C++ (for example), and each type (and object) in the scripting language has a corresponding type (and object) in the underlying implementation language. The base class in this imaginary type system is a class called Object, and all other classes must derive from this class. Now, you have another class called HashTable, which is the basis for all variable storage (I might have said that wrong): namespaces are implemented via HashTables (associating one object with another object), global variables are stored via HashTables, and, to the point of the problem, instance variables are also stored in HashTables.
Instance variables are such that every Object has an HashTable in which to store its instance variables. However, HashTable necessarily derives from Object, therefore each HashTable has an HashTable in which to store its instance variables. And every HashTable for every HashTable has an HashTable, and so on ad infinitum.
My question is, can this type system be implemented in an object-oriented way in the underlying C++ code? If no precautions are taken, the program will enter an infinite loop and cause a stack overflow on the mere instantiation of an Object, because it will instantiate an HashTable which will call its parent constructor for Object, which will instantiate an HashTable...
Are there any viable workarounds for this design flaw which don't involve breaking the desired OO design (each type has its corollary type in the underlying code)?
Pardon the grammar in this post, English is not my first language and I might not have explained something in a comprehensible manner.
implement two different HashTable types: one for user code (UserHashTable), derived from Object and so no violating your "everything is Object" rule, and another for internal use (CoreHashTable) to implement your type system.
[EDIT] CoreHashTable can be automatically convertible to UserHashTable, e.g. UserHashTable can contain internal smart pointer to CoreHashTable.
Yes. You can emulate your own "object system" with another programing language.
That concept its called a "virtual object system".
O.O. Programming languages have its own "Object System". By an "Object System", I don't mean "O.O. libraries or O.O. Class hierarchy". By an "Object System" I mean its way of declaring and using classes and objects.
But, sometimes, your programming language its not object oriented, or even if its object oriented, some stuff is missing. C# and Java doesn't have real properties & events, C# and Object Pascal does.
When O.O. started, many programmers use non O.O. programming languages, and learn about O.O. Some make their own "plain C" to "C++" preprocessors (Objective-C maybe), some did full compilers.
And some emulate them. The programmer, conceptually, thinking, he was using classes and objects, but, in code, use structures & pointers.
I have seen several "virtual object system (s)", where a group of classes or objects is simulated by another programming language.
Once, I worked with a database conectivity tool called "Borland Database Engine", where developers read and write data into objects like "databases", "tables", "fields".
One famous, is the GLib library ("GObject" is the root object), used in the GNome visual interface for GNU/Linux. It's done in "plain C", but simulates objects and classes, using pointers.
More Info:
http://en.wikipedia.org/wiki/Gobject
You want to use a group of objects conceptually speaking, but in code, you won't have a class declaration for your conceptual class, but, some data stored in hash tables, using another O.O. programming language. Yes it can be done.