+ 8
Why OOP is required in a programmer’s life?
We have all probably heard about “object-oriented programming”, “OOP”, “classes”, “inheritance/encapsulation/polymorphism”, and other computer science terms but still don’t get what exactly OOP is used for. In this post I want to help myself and many others here, can anybody easily explain what is the "OPP"? and How it's work? Your contributions are welcome. ^_^
5 odpowiedzi
+ 7
OPP allows us to organise around objects instead of actions.
Here is a simple example that creates different types of creatures all off a single base. This way they all share common traits yet have thier own unique ones as well.
In this example the base has a method called talk. The base has no voice. But all derivatives have a voice. Each unique.
Edit: Basically it makes code more modular and easier to extend, maintain and modify.
https://code.sololearn.com/c2K6GIK5R5Ek/?ref=app
+ 4
Classes are absolutely required, you need to understand how you can access other files from the same or different packages. Plus it organizes your code and separates what each object does. It also allows you to create an object of the class with everything neccessary to the object inside the class.
Inheritance allows you to access any non-private member from the extended class. Thus, reducing the amount of work you need to do greatly, and if you create an object of the super class you will also have the sub classes and vise versa.
Here's some explanations on Polymorphism, would be better explained by them then me:
http://stackoverflow.com/questions/2080020/what-is-the-real-significanceuse-of-polymorphism
You use Polymorphism all the time. Anything that a float has, that an int has, is Overrided from the Object class. Such as: Integer.MAX_VALUE; Or Integer.tryParse. (Depending on the language for this exact syntax)
Take a look at my OOP code here, hopefully it gives you a sense of the practical use https://code.sololearn.com/cZKcrU0TrMtX/?ref=app
+ 3
before oop, it was more difficult to enforce good organisation of code, leading to 'spaghetti code', where modifying libraries had more risks breaking features accidentally (because of unexpected dependancies.. )
OOP is helping a bit by providing a common way of thinking, so it is easier to find where code is, and less likely to add dependancies to 'private' code.
+ 2
The purpose of a programming language is to express the solution to a problem with the help of an algorithm. The success of the solution depends on how well the solution models the problem. OOP is required in programmer's life so that the program which he/she is developing, it actually matches with his/her view on our world. Also, problem solvers do not perceive the world as data and methods differently. They concentrate on the objects and let the characteristics of the objects tell them which tools and procedures are required to apply.
0
c++