Why OOP is so confusing?[Solved] | SoloLearn: Learn to code for FREE!

+4

Why OOP is so confusing?[Solved]

I have seen OOP in many major languages like python and Java but it seems vary confusing to me . Can any one help me with that? Thanks in advance

9/27/2020 4:57:02 AM

Arnav Kumar

44 Answers

New Answer

+6

Ore Nice run through of the high level talking points for class based and prototypal based inheritance / OOP. \•/ It's always nice to meet a fellow veteran programmer here who has also been working with Java since it was released - or shortly thereafter. 👌 jack I completely agree that, in C#, pretty much everything is an object. Even the equivalent of Java primitive types are actually value types in C#, which inherit from System.Object like everything else in the CLR. C# also supports delegates, which is basically the class equivalent for defining function types. Kotlin is the closest to C# of the statically typed languages in these regards. For those who want to really bend your minds with some cool C# Voodoo black magic, check out this code I created for another question where I demonstrate the ability to create class properties at runtime on demand. This code also uses explicitly typed properties inherited from an abstract class and other classes. https://code.sololearn.com/c0KhE05NCS76/?ref=app

+5

Try a bunch of OOP courses on DataCamp, Coursera or right here. Multiple tutorials are on the Play Store as well.

+5

You do not have to use classes - just go functional programming and do your best as, perchance, OOP is not for you. Try to get on with Machine Learning and Data Science then.

+4

Lothar I got confused with concept of classes ,encapsulation,polymorphism, inheritance and their syntax look a bit hard to understand can you please explain me the concept of Object Oriented Programming easily . I learnt OOP in Sololearn w3schools also but I am stil confused with its syntax.they look so vast😱😨

+4

Maybe because it's more complex than procedural programming.

+4

There is way more to oop than i mentioned above. If you're really interested in learning oop i suggest to invest money in a propper book or two. And i dont mean clean code and such. Start with the basics do projects and repetition, repetition, repetition. You'll eventually get there. P. S. Unlike the others i won't suggest to watch any youtube videos on oop. The topic ( as is common in programming) is so vast that you can't comprehend whats happening from watching some videos. My expirience is that you get even more confused because people tend to do things very different and dont explain everything in the detail you need, to make sense out of it. You end up like a monkey typing code you dont understand, because you lack the basics. If you watch videoes on YouTube choose the ones that try to explain a certain problem, not a topic or a whole idea.

+3

Have you gone through the Python or Java course herein?

+3

Just think of the class as being a place to put all the ingredients like properties and methods needed for your object. Once you have done this you will have to create an object from it, the object is like a self contained usable version of the class that contains all the ingredients for you to use. If you create 2 objects of the same class both objects are seprate from one another just like in real life when you see 2 identical cars which look the same but you know there 2 separate objects that have there own properties ie one car gets damaged but the other is intact.

+3

Arnav Kumar PART 1 ====== OOP is a complex paradigm that I can not explain completely here. I hope to just give an introduction and leave you to learn it yourself somewhere else. The whole idea of object oriented programming is to encapsulate related data into small objects. These small objects have their attributes and methods with which they interact with other objects in unique ways. The interaction between several of these related objects make up the bigger picture. An analogy: The real world is full of many objects, both living and non-living. These objects exist independently and have their own internal state some of which may not be accessed directly by an external medium. But these objects interact with each other to produce the bigger picture. That is what OOP feels like. About the connection between JS and Java objects: They are similar but not exactly the same. ....will continue in another response

+3

PART 2 ====== JavaScript objects, as a matter of fact, need a blueprint for construction. This blueprint is called prototype. If no prototype constructor is provided, the base Object prototype is used. So `{}` is similar to `new Object()` A class (actually an object factory in JavaScript) can be created as in other languages. class Human {} To further understand OOP there are many terms which you must understand. I will explain some of the common terms here. Attributes: variables that hold state of an object or hold references to other objects. Methods: Functions that are specific to an object. They will likely modify an object state or return the state. Encapsulation: The process of grouping related data into a class and setting modifiers on which objects can access the said data. Inheritance: When an object extends another object by inheriting its blueprint and adding new attributes and/or methods to the blueprint. Composition: When a object stores a reference to another object has an attribute.

+3

PART 3 ====== Polymorphism: The ability of a class to produce objects of different form. Constructor: A function that describes actions to be performed when a object of a specific type is created. Destructor: A function describing actions to be performed when an object lifecycle has expired. There are so many other terms. It will be wise to seek a good tutorial on this subject. But hopefully this is a good introduction.

+2

Ya I have completed java kotlin c++ and python without understanding OOP and just ignored them

+2

I am confused with objects and classes in JavaScript we use objects they have methods properties but in other programming languages like python there is no object like in JavaScript there are classes that look like objects in JavaScript they also have methods and properties . I know that the classes are like the blueprints for making objects but in JavaScript I can make objects without using classes so why I do need to use classes there

+2

Lothar I am good at functional programming but the concept of class and objects and their properties and method are confusing me Though I can make objects in JavaScript write there properties and methods vary easily but when it comes to make an object using classes it seemed to be hard for me

+2

Public means as much as other parts oth your programm can see this property or method as well. Private means just the opposite, only members of this class can see methods and property so they wont be accessible in other classes. Void is a return parameter that defines that a method ( js the equivalent would be function) has no return therefore the keyword return is not valid with any return type ( can still be used to exit the function) Protected is much like private except that its visible to derived classes ( Inheritance) Internal is only visible with in you application/ programm. Virtual makes classes available to be overridden using the override key word. Most commonly ToString() method in c# is overridden to adjust the string output ( i doubt your user wants to know the type of class youre using so you have to adjust output) Thats that in short

+2

Arnav Kumar You do not need to have a glossary while learning. As you learn, you will discover new things and understand new terms gradually.

+1

But I want to learn oop!

+1

Is it the syntax of the languages or ... If this is not about the syntax, then let me help u out. OOP is a "technique" used to simulate real world entities in that everything is an object. For example a person is an object and this simply means a person has certain behaviour ( actions) like eating, speaking etc and attributes like age, name, DOB etc. That is what OOP is all about ie methods and properties. Wish I luck

+1

Kirabo Ibrahim no it's syntax can you help me with that

+1

D_Stark I know how classes and object relate to real life objects Can you please help me with the code syntax of classes and objects and keywords used in them