tags:

views:

444

answers:

5

C# Supports 4 basic features of object oriented languages:

  1. Abstraction
  2. Encapsulation
  3. Polymorphism
  4. Inheritance

Can I say C# is a fully Object Oriented Programming Language? Why?

A: 

Some purists will insist that C# is not fully object-oriented because it lacks multiple inheritance.

Steven Sudit
What languages out there allow for multiple inheritance and how do they get around the diamond problem?
myermian
Lacking multiple inheritance does't disqualify C# as Object-OrientedIt is just an additional feature of other languages like C
Carlos Muñoz
Carlos: Not sure I disagree with you. Just saying that the *purist* view requires multiple inheritance, which is reporting a fact.
Steven Sudit
@myermian: Well, C++ is a good example. It offers abstract inheritance as a way to avoid duplication.
Steven Sudit
+1  A: 

No one knows what "100% object oriented" means. Probably C# is not since not everything is an object.

Some things that aren't objects:

  1. Blocks of code. True, you can have an object like a Func which is a block of code. But in some languages, all the code is actually objects.
  2. primitives (int, float, double, short, etc.)
  3. functions
tster
What's *not* an object?
Steven Sudit
@Steven Sudit: unmanaged pointers are not object afaik.
ShdNx
@ShdNx: But should we consider unmanaged code as a true part of C#, or just an extension to make C# interoperable with external (possibly non object-oriented) systems?
Jason Williams
But I bet it would sound great to the marketing department.
Dr. Wily's Apprentice
@ShdNx: In addition to Jason's point, you're only half-right. IntPtr is an object, but unsafe pointers are not because, well, they're unsafe. Their lack of safety comes from the fact that they necessarily stand outside the object model, treating objects as bytes.
Steven Sudit
1) Blocks of code are expression trees, which are first class objects that can be used as delegates 2) This is only half-true, at best. An unboxed int is still an object, even though it doesn't share the standard memory representation until it's boxed. This is C#, not Java! 3) Functions are delegates, wich are first-class objects..
Steven Sudit
@Steven Sudit, 1. Blocks of code **can** be expression trees. Not all are. 3. I don't think it is safe to say that functions are delegates.
tster
@tster: 1) The ones that you want to use as objects can be kept in expression trees. 3) Really? I can pass a function to any method requiring a delegate. If the two are not identical, there is an implicit conversion.
Steven Sudit
+5  A: 

It depends on your definition of "Object Oriented Programming Language".
Using your definition, yes C# meets 100% of the requirements:

  1. Abstraction
  2. Encapsulation
  3. Polymorphism
  4. Inheritance

However, C# contains features that aren't strictly "Object Oriented" such as

  • Enums
  • Value types
  • Static methods
  • Static classes

So I would say that, regardless of the definition you want to use, C# is not a pure Object Oriented Programming Language.

Greg
Then what is the actual definition of Object Oriented Programming Language?
chanchal1987
If only I knew what he meant by Abstraction.
Steven Sudit
@Steven - Who knows. Since C# has abstract classes and allows one to write "abstractions" (like any programming language), then I'll say that it fulfills this vague requirement.
Greg
Actually Enums **are** objects. They derive from **Enum** which derives from **ValueType** which derives from **Object**
Carlos Muñoz
Static methods and classes don't strike me as "not OOP" since I don't know of any OOP languages that don't have them. Now, Value types I might accept but, given the origins of OOP (AI), I think that you'd have to be more of a purist than the originators to hold this against them.
Mark Brittingham
@Carlos - Technically they are objects, but really they are value types, which are second class citizens in .NET. Enums are even lower class, they can't even have methods. I'm not complaining about it, but it sure isn't very Object Oriented.
Greg
1 + 2)Enums and value types both inherit from System.Object. 3) Static methods are delegates, which are first-class objects. 4) Static classes are classes: classes are objects.
Steven Sudit
@Greg: Yeah, I've never actually heard Abstraction listed as a requirement for OO.
Steven Sudit
+1  A: 

Lots of features make C# not totally object-oriented. However I don't believe any language is 100% "object oriented" and (almost?) all languages are at least a bit multi-paradigm. For instance, delegates. A very biased source points out that delegates, a construct in C# that I love, is not a "first class citizen" among objects. Java doesn't support multiple inheritance but I believe that's the most object oriented language there is. C++ does but is clearly not 100% object oriented, as a 100% function-based C++ program can easily be written (just compile almost any C program).
It depends more on the use of the language than the language itself. It's oriented towards objects but not exclusively comprised of objects, just like other languages. Will answering this question help anyone write significantly better code? I personally don't think so -- Richard Feynman said "I learned very early the difference between knowing the name of something and knowing something." It doesn't matter if it can be called "object oriented" as anything from Perl to Python to CIL to Ada has object-oriented features, and C# has features that are not object oriented.

bowenl2
I think Ruby is more object oriented than Java....
tster
+1  A: 

Yes, you can say that C# is a fully object-oriented language. Think of it this way, it not only supports the four criteria of OOP, it also requires that essentially all of your constructs be encapsulated in objects (enums or value types not being pure OOP wouldn't sway me as being a particularly important exception). That is, C# doesn't let you develop outside of the OOP methodology in any meaningful way. Where people sometimes say a language isn't truly OOP is where object orientation is optional - such as C++ where you can develop in pure C if you wish.

One note: Steven points out that it doesn't support multiple inheritance. However, that doesn't disqualify it: OOP isn't dependent on the inclusion of this feature (and experience has taught us that it is, at best, a mixed blessing). That would be like saying that a car isn't a "car" unless it has a back-up camera since some cars have them.

Mark Brittingham