According to Grady Booch "Object oriented analysis and design", programming without inheritance is not object oriented that is called as programming with abstract data types. if am developing one application using c# with some classes with out inheritance,is this is object oriented(because the language is object oriented) or not?
-
1What's the issue with not programming in an object-oriented way using an "object-oriented" language?Alex R.– Alex R.06/23/2011 06:44:10Commented Jun 23, 2011 at 6:44
-
@Alex: +1. I didn't get the memo about OO being the only acceptable paradigm (in C# or anywhere else).cHao– cHao06/23/2011 06:51:37Commented Jun 23, 2011 at 6:51
6 Answers 6
Object-oriented programming is the concept of using objects, e.g. classes, structs with fields, properties and methods to encapsulate programming logic.
Inheritance is a feature of many OO languages, but not a necessity. The ommitance of that feature, doesn't make an OO language a non-OO language. So, I don't agree with Grady Booch's understanding of what OO is.
If you're programming with C#, you're using an OO language, you can't get away from that as everything inherits from System.Object
at least.
-
5For reference, Grady Booch invented the "Booch method" (which was eventualy absorbed into UML), and wrote the foreword for the GoF book. Just saying...you picked a heck of a guy to disagree with about OO. :)cHao– cHao06/23/2011 07:01:15Commented Jun 23, 2011 at 7:01
All classes in C# inherit from object so yes its object oriented :)
-
This is more a case of purity. You can go the Java route (primitives and objects) simula (no primitives) or C# (lets make primitives look like objects even though they aren't.)Spence– Spence06/23/2011 06:46:54Commented Jun 23, 2011 at 6:46
-
1Documentation for object base class : msdn.microsoft.com/en-us/library/9kkx3h3c(v=VS.100).aspxbasarat– basarat06/23/2011 06:51:08Commented Jun 23, 2011 at 6:51
Refering to Object-oriented programming:
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction, encapsulation, messaging, modularity, polymorphism, and inheritance. Many modern programming languages now support OOP, at least as an option.
Simple, non-OOP programs may be one long list of commands. More complex programs will group lists of commands into functions or subroutines each of which might perform a particular task.
In contrast, the object-oriented approach encourages the programmer to place data where it is not directly accessible by the rest of the program. Instead the data is accessed by calling specially written functions, commonly called methods, which are either bundled in with the data or inherited from "class objects" and act as the intermediaries for retrieving or modifying those data.
An object-oriented program will usually contain different types of objects, each type corresponding to a particular kind of complex data to be managed or perhaps to a real-world object or concept such as a bank account, a hockey player, or a bulldozer.
Objects can be thought of as wrapping their data within a set of functions designed to ensure that the data are used appropriately, and to assist in that use.
So, inheritance is a key consept of the OOP but still you can write OOP applications without using it.
If you have developed some or one classes there is Object Oriented Programing , C# is the full OOP Language if you don't use inheritance by default your classes derived from base class object. There is no problem if you don't use inheritance any way if you create classes and object there is OOP design
There are many ways to look at it--everyone has their own definition of "Object Oriented".
To be an effective OO programmer, polymorphism must be a part of your toolkit, it's too useful to ignore--not only that but you should be able to use it effectively which means also making use of encapsulation over inheritance whenever possible.
It also means creating objects that have methods that modify their data before methods that hand up data to another object to be modified (Property style coding is bad OO in other words)
I guess I'm saying that you shouldn't force using inheritance all over the place but it's useful enough that if you aren't using it beyond everything inheriting from Object you really shouldn't be calling your code OO--this is true even of fairly small apps.
-
I agree with the part about *Composition over InheritanceSuamere– Suamere08/10/2017 19:49:57Commented Aug 10, 2017 at 19:49
-
Of course not everything should be OOP. It is a technology not a universal panacea.Samantha Atkins– Samantha Atkins05/20/2022 02:02:43Commented May 20, 2022 at 2:02
-
@SamanthaAtkins Totally agree. I was just suggesting not calling it OO code if you aren't doing OO, C# has the ability to use other development paradigms.Bill K– Bill K05/20/2022 02:46:42Commented May 20, 2022 at 2:46
You can write bad code in any language...
Seriously though, if you are using the .Net framework with C# then this is built strongly on OOP principles. Every time you use a collection, windows forms, WCF any of the multitude of classes in the framework, you are using OOP.
-
you are using - but not necessarily doing - have a look on my answer.Kamil Tomšík– Kamil Tomšík06/23/2011 22:46:44Commented Jun 23, 2011 at 22:46
-
So when I create a SqlConnection class and then create a connection this isn't OOP? Thats what I meant, the .Net framework is designed using OOP, so if you use it you are inherently using OO. However you can then create a procedural mess of static methods on top of that if you feel so inclined.Spence– Spence06/23/2011 23:30:58Commented Jun 23, 2011 at 23:30