+ 11

What features makes a program Object oriented?

I wonder why is C not Object oriented and C++ is object Oriented. In the same way what is the relation of OOP with GUI?

30th Mar 2019, 5:47 PM
Byk
16 Respostas
+ 14
An OOP language should allow inheritance, polymorphism and encapsulation (as a minimum?). You want to be able to create an object/instance with a specific shape that protects its data and only allows access via an interface. Using inheritance, methods that do different things can carry the same name. I guess you can 'sort of' create objects with C... But I'll let people explain who understand it better. https://stackoverflow.com/questions/1237266/how-can-inheritance-be-modelled-using-c
30th Mar 2019, 6:16 PM
HonFu
HonFu - avatar
+ 10
The answer to the subtext of your question is that C++ has classes while C does not. In addition, there is no direct relationship between support for GUIs and OOP. C can also do GUIs via libraries. As HonFu mentioned, an OO language needs those three essential properties. As to your main question of what makes a program (rather than a language) object oriented, I guess the answer is that it needs to have at least a single class. C++ allows for programming without classes (in a C style) as well as for programming with classes and objects. So a C++ program written in an older C-style without classes will not be Object Oriented. It's very interesting how non object oriented languages like C can also be used to model OOP concepts via nested structs (inheritance), function pointers (polymorphism) and encapsulation (via which files are used to define/store data members). However, unless you're stuck with C as a language it's always better to use a standard OOP language (Java, C++, Python etc.) to model objects.
31st Mar 2019, 10:05 PM
Sonic
Sonic - avatar
+ 5
An object is an "thing" that uses messages to communicate with other objects. So I think the bare minimum to deserve the title of "OOP language" is that you need "things" with methods and properties. (Classes, Inheritance are nice to have but not strictly necessary, javascript didn't have either for a long time!) C fails because structs don't have methods. Structs are lifeless data containers that can never *do* anything on their own. But as others have said you can write OO code in C if you get creative. OOP-ness of a language isn't a simple yes/no question but it's a spectrum, with C almost at the bottom. Python has pretty minimal OO and is a step up, C++ sits somewhere in the middle and languages like smalltalk/ruby/java fight over who is peak OO.
31st Mar 2019, 10:55 PM
Schindlabua
Schindlabua - avatar
+ 4
Object. Class. Data Hiding and Encapsulation. Dynamic Binding. Message Passing. Inheritance. Polymorphism.
31st Mar 2019, 4:48 AM
Dan Rhamba
Dan Rhamba - avatar
+ 3
I just say my understanding of oop. Unlike c, java and c++ encapsulate the qualities (attributes and functions) into the objects. When the client wants to invoke the attribute or the function, he should build an object to invoke them, and he doesnot need to know how they are implemented. The objects expose their qualities to the outside, and conceal the implemenatation code. C is quite the opposite.
31st Mar 2019, 11:29 AM
rookie_
+ 3
Schindlabua, I have trouble understanding the dispatch thing... guess I'll need to read up on that. Python has primitive types? Even something like int or double have big lids on and a lot of methods attached to them. What primitives are you referring to? Also classes, functions and all of that are objects in Python (3). Aren't the 'magic methods' what you are looking for with special syntax for constructors (and a big set of other functionality)? And don't C's struct also use dot notation?
1st Apr 2019, 8:40 AM
HonFu
HonFu - avatar
+ 3
Actually the thing is Object Orientation is also a design methodology, so you can do object oriented programming in non-oops languages too like C. Although an OOPs language is more suitable and equipped with several constructs and features favorable for oops programming, non-oops languages can serve the purpose too.
1st Apr 2019, 12:37 PM
Junaid Siddiqui
Junaid Siddiqui - avatar
+ 2
When you think of OOP simple think of Classes Objects Polymorphism Abstraction Encapsulation Inheritance Good thing these aspect don't change in all the programming languages there definition and implementation stay the same.
31st Mar 2019, 6:26 PM
Oscar
Oscar - avatar
+ 2
Schindlabua, can you elaborate a bit on the order you gave? When I read the Ruby tutorial, I had the impression, Python and Ruby were relatively similar in their setup; but the tutorials do stay quite at the surface. I was surprised, anyway, to see you call Python's OOP 'minimal' while Ruby settles at the OOP side of things. Python has classes, multiple inheritance, operator- and functionality overload, you can import more functionality like abstract base classes... What exactly is missing that led you to placing Python only one step away from good old C? (Except data hiding - we talked about that in the other thread.)
1st Apr 2019, 7:47 AM
HonFu
HonFu - avatar
+ 2
HonFu It's not so much missing features, and I don't mean it in a bad way! Syntactically it always felt like python wants to remind you that OOP is nothing but single dispatch. Like, you always have that explicit first parameter called self. Constructors get no special syntax, they're just another method. That's exactly how you would implement "methods" in C, so the difference here is just that python packages it up neatly in a "class" and C doesn't, and python gives you dot-notation. I wasn't aware of @abstractmethod! Nice that there's a way to do it, but it's also "tacked on" and not really a language feature. (EDIT: Also I'm an idiot, in python everything is an object. For some reason I thought there was some java-like duality going on. Maybe I should reconsider :P) Ruby though... it's late-stage OOP. Everything is an object, even classes are objects. Each object gets an "eigenclass", which is also an object, and you can subclass the eigenclass at runtime. Google "class << self"!
1st Apr 2019, 8:20 AM
Schindlabua
Schindlabua - avatar
+ 2
HonFu Yeah I just edited it. Goes to show how much I know! I guess that puts python up there. Maybe I confused it with PHP, I also thought classes weren't in Python from the beginning. Shame on me! C structs use dot notation, but hypothetical "methods" you implement in C don't. I guess I put C++ higher because you have things like virtual inheritance and private inheritance and function try/catch and friend functions and generics and whatnot and python keeps it pretty basic. But maybe I'm talking bs and OOP-ness is not as simple to judge as going from low to high!
1st Apr 2019, 9:05 AM
Schindlabua
Schindlabua - avatar
+ 2
About virtual methods in Python: https://stackoverflow.com/questions/4714136/how-to-implement-virtual-methods-in-python And there is exception handling in Python! It's only called try/except instead of try/catch. I guess friend functions are not necessary because there's no real privacy to begin with, so you don't need to create this sort of 'ambassador' object.
1st Apr 2019, 9:12 AM
HonFu
HonFu - avatar
+ 2
No I meant function try catch blocks which explicitly handle exceptions thrown in constructors and such :) And C++ gives you the option to choose whether you want to inherit virtually or not. So lots of fluff whereas python doesn't need it and goes for minimal syntax.
1st Apr 2019, 9:20 AM
Schindlabua
Schindlabua - avatar
+ 1
C is the not object oriented languages because C wasn't designed to be Object Oriented, it lacks various built-in constructs that you'd expect in OOP languages, such as: Classes. Interfaces. c++ contain the classes and inheritance thats why c++ is object oriented. If you want more knowledge on this topic please visit http://pythonandmltrainingcourses.com/best-summer-training-in-noida/
1st Apr 2019, 7:07 AM
navdeep
+ 1
Object oriented programming also called as oops programming paradism is not present in c because in C language we give impotance to code rather than data and there is no security for our data whereas in C ++ which may not be totally object oriented but a partial one it gives importance to data rather than code ascess specifiers made this possilble and do u know why c++ is partial ooops concept because of a function called friend
6th Apr 2019, 4:12 AM
Yarlagadda Gopi Sri Krishna
Yarlagadda Gopi Sri Krishna - avatar
0
You can create classes thats it Means you can build bigger and complex programs which perform much functionalities Else all languages have same program logics And you can perform oop concepts only when you work with classes but c has no class concept
2nd Apr 2019, 5:50 PM
Tony Stark
Tony Stark - avatar