well i am having lots of question regarding to the desired topic,well its better to be short here.
1> C# is object oriented or object based
2> java is object oriented or object based
as per my knowledge c# is object oriented and java is object based,if it is true then what makes java to be oriented not object oriented.
Object based programming paradigm makes use of all the features of object oriented programming except for inheritance. For example JavaScript is object based whereas Java is object oriented.
Although it is common to use these two terms mutually exclusively, practically speaking, an object oriented language is also object based but not vice versa.
Both C# and Java are object-oriented languages.
Generally, a language is regarded as "object-based" when it lacks support for certain central features of a truly object-oriented language, namely inheritance and polymorphism. A good example of an object-based language is VB 6 (the pre-.NET version). It was based on objects, but it did not support either inheritance or polymorphism, making it impossible to regard as a truly object-oriented language.
Related
I heard that interface is introduced as a way for making up that a object-oriented language doesn't support multiple inheritance but only single inheritance.
Is interface merely used for that purpose?
Is interface ever useful for a OO language which supports multiple inheritance?
Thanks.
The book "Design Patterns" strongly stresses the importance of interfaces and at the time it was written, C++ (with multiple inheritance) was the most popular OO language and Java didn't even exist yet. (The book was published a year before Java was released.)
It's important to understand the difference between an object's class and its type.
An object's class defines how the object is implemented... In contrast, an object's type only refers to its interface—the set of requests to which it can respond.
...
It's easy to confuse these two concepts, because many languages don't make the distinction explicit.
...
Many of the design patterns depend on this distinction.
This book coined the term "Program to an Interface, not an Implementation."
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
I grew up being taught java, and I've started to learn a lot of PHP over the last few years using popular open-source CMSs. I really love the natural-feeling of OOP, but I've more recently discovered the concept of functional programming, which appears to be a difficult but elegant way of doing things.
In rtperson's great answer to the question "What is functional, declarative and imperative programming? [closed]", he says that "Then there's Object-oriented programming, which is really just a new way to organize data in an imperative program."
I think I understand what he means by that, but is it strictly true? Can OOP co-exist with functional programming?
Yes, there is a term of "object functional programming".
Basically in those languages a function is a "first class citizen" - an object.
I guess most agree it is not so easy to get there just because you have to know about all concepts - functional, OO and imperative.
Examples for such languages are:
Scala (I like it very much)
Boost::function , Boost::bind in C++
.NET F#
javascript (aka ECMAScript)
Yes it's compatible. You can program in a functional way in any language. An example would be Java String which is immutable and returns a new object if you do altering methods such as change case etc.
If you think about it o.something(y) is just osomething(o, y) and if you don't mutate o or do other side effects not related to OO it's functional.
Yes. There is something called a 'functional object', which is basically an object where the mutator methods, instead of changing the state of the object, return a new object with modified state. Clean combines that idea with uniqueness types to keep the modified states single-threaded, which allows the compiler to implement methods by modifying the storage for the object behind the scenes.
Furthermore, there's nothing about mutable state that makes it 'not purely functional'; what's impure is when ordinary expression evaluation mutates state that's visible to the program. So you can combine OO and purely functional programming by making your object's methods return actions in the IO monad (or any other stateful monad) that mutate a common set of underlying state (not available to the rest of the program).
In DCI discussions, there is a usually mention of pure object oriented languages:
Object-oriented programming languages—particularly the "pure"
ones—expressed everything in terms of objects or methods on objects.
(Of course, most programming languages used classes to do this.
The point is that nothing was supposed to exist outside of an object framework.)
Source: http://www.artima.com/articles/dci_vision.html
I'm trying to understand the difference between a pure OO language and a non-pure one in terms of DCI. To help put the differences into context, it would be good to have an example of a pure OO language so that I can contrast it with my experience with class based language such as java.
Question: What languages are pure OO languages (from the perspective of DCI)?
A non-pure OO language in this context is a language were not everything is objects. Java for example have "primitive" types, which behave differently than objects. For example, Java's primitive types are passed by value, while Java passes references when it passes it's objects.
In contrast, Python treats everything as objects, and although it has built-in types, it has no primitive types, everything is objects.
I think you misunderstand the reference to classes. I don't think they say that a pure OO language does not have classes.
As per my knowledge, Objective-C is an Object oriented programming languge and Categories is a feature provided by Objective-C.
So I would like to know that Category feature is coming under which OOPs concept
Abstraction
Polymorphism
Encapsulation
Inheritance, etc.
Thanks in advance.
Mrunal
#Abizern's answer is good. I would add that categories are a form of dynamic dispatch, in particular that they can be used to extend existing classes without subclassing.
That said, Object Oriented Programming is more a design philosophy than a set of language features. One might ask "what OOP feature does postfix increment correspond to?" The answer is "none; it's a language feature." Categories are not primarily used to implement OOP design (though sometimes they are, as noted above). Their original use was to break up large implementation files. Their later use was to provide informal protocols due to a flaw in the language (lack of #optional). And today, they're primarily used to split code along platform-specific lines (NSString+UIStringDrawing vs NSString+AppKitAdditions).
Extensions are similar to categories, and similarly are primarily a language feature rather than an OOP design feature. They facilitate encapsulation to some extent, but mostly are a side-effect of an arbitrary compiler requirement to define methods before they are used (I say "arbitrary" because this is not related to design or developer needs; it just simplifies the compiler). Extensions should not be confused with some deep OOP requirement.
So using categories to attach additional functionality at runtime is dynamic dispatch. Beyond that, it's just a language feature that's used for several non-OOP things.
According to the Cocoa Design Patterns book by Buck and Yacktman. Category is a pattern in itself, and one that is supported by the Objective-C programming language directly.
Probably closest to Encapsulation, when it comes to academic OOP concepts. But this really shows the difference between academic definitions of OOP, and the practical world of OOP Design Patterns.