OO allows for logic related to an object to be placed within a single place the class, or object so that it can be decoupled and easier to debug and maintain. What I have observed, is that every app is a combination of OO and procedural code, where the procedural code is the glue that binds all your objects together at the very least, the code in your main function.
The more you can turn your procedural code into OO, the easier it will be to maintain yor code. It depends by the problem: the OOP paradigm is useful in designing distribuited systems or framework with a lot of entity living during the actions of the user example: web application.
The language OOP is useful because too it use probabily the garbage collector automatic use of memory in the run of program: you you program in C a lot of time you must debug and correct manually a problem of memory. OOP is useful when you have things. A socket, a button, a file. If you end a class in er it is almost always a function that is pretending to be a class. TestRunner more than likely should be a function that runs tests and probably named run tests. Personally, I think OOP is practically a necessity for any large application.
I can't imagine having a program over k lines of code without using OOP, it would be a maintenance and design nightmare. When the architect writes really complicated, non-documented OOP code.
Leaves half way through the project. And many of his common code pieces he used across various project has missing code. Thank god for. NET Reflector. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. When is OOP better suited for? Asked 13 years, 3 months ago. Active 3 years, 4 months ago. Viewed 16k times. Improve this question.
Henrik P. Hessel Add a comment. Active Oldest Votes. Improve this answer. Xetius Xetius Perl's OO is really powerful, if really ugly and barebones.
Perl 5. To update it at that time would have involved a massive change to a large number of servers and the whole support infrastructure. That has all changed now though, 2 years later. Mike Stone Mike Stone I am sold to OOP. Anytime you can define a concept for a problem, it can probably be wrapped in an object. Your model is a simulation of something OO excels at simulations. Michael Langford Michael Langford 51 2 2 bronze badges.
Also, there are times when a functional approach would make more sense such as this example taken from MSDN : Consider, for example, writing a program to convert an XML document into a different form of data. I find it helps to think of a given problem in terms of 'things'.
Chris Roberts Chris Roberts For procedural programs algorithms are critical to learn how to put together disparate statements and functions to do useful work. You need a more skilled programmer to prevent software rot. Over time, the more skilled programmers are pulled off old code to work on new things.
So the old software slowly rots. The problem is with the programmers. Where Scala truly shines is in its powerful support for OOP.
I would argue that only a tiny fraction of the code that is deployed in the real world is object-oriented. In fact, both Java and C make it incredibly hard to write object-oriented code, if not plain impossible. Guy L. The orgin idea of OOP was to solve the problem of spagetthi code of the procedural programming: A change to a data structure often leads to change many files and code.
If you take a look on real world java projects e. They still follow the procedural programming: fetch data getter , calculate, store data setter. Is it also not surprising that such projects produces spagetthi code and are really bad to understand and to maintain. My static code analysis is to count grep the getter and setter per line of a project.
At the beginning i was also blinded from the ideas of polymorphism, inheritance, multi-inheritance, late binding and the discussion about what are good and OOP-Patterns GangOfFour. Information hiding? Yes, that means private fields!? Cook, but it has been known for far longer than since Of those folks, all lack the fundamentals of what OODA actually is and held tight to functional programming the only form of programming they understood from a several decades before.
Perhaps because they apply it correctly, perhaps because they were properly trained in it, or perhaps because they tend to work on sophisticated complex systems that tend to demand encapsulation, data abstraction and such. Could you please fix your very irritating and blatantly untrue title? Why people dislike OOP?
Is that actually true? Our industry tends to have some stereotypes and from time to time they suddenly claim to like one approach or another, there is no silver bullet, each approach has pros and cons, live with it. According to Uncle Bob Robert C. Martin , only polymorphism is really a feature of OOP. He claims that C had perfect encapsulation with the separation of header files and encapsulation files.
Inheritance was also possible by the use of pointers in structs. I believe the reason why OOP projects go wrong is because of a lack of knowledge, experience and discipline on the part of developers.
Then, when they learn about interfaces, they use them everywhere, even when not needed. Finding the right abstractions and the right level of abstraction is an art and requires experience.
Same thing for Design Patterns. Developers go from being ignorant about them to using them everywhere. An experienced developer only use them when needed and know which one to apply and when.
It might be due to the fact that half the developers have less than 5 years of experience. Who hates OOP? Are people having anger management issues? Another tagline — if everyone hates death why is still so widespread? In fact, I love it. I am sure that without OOP, programming would be harder and more error-prone. I was programming in the 80s. OOP was a revelation. Before OOP, you had libraries of functions. You had to keep track of which functions were allowed to use which structures.
If you needed a new structure that was similar to, but slightly different from your old structure, you had to copy it line-for-line to the new structure — meticulously maintaining the order of the members.
I think the writer has it all backwards. We got OOP and were so relieved with the simplicity of the languages. It was not the very first OOP language, but it was the first one to become widespread, so the problems with it showed up far better than in earlier languages like Simula.
He openly admitted, for example, that making it so highly back-compatible with C made the language a lot uglier than it had to be. It made support for OOP ways more cumbersome than it had to be, too. Another installment in the series of misguided articles denigrating OOP. I am surprised it is published on stackexchange, a network that is itself powered by an OO language. A lot of commenters have already pointed out the usefulness of OOP paradigm in terms of human readability and understanding.
I started my career working on ATM, and have a deep cynicism towards over-hyped things as a result. There are some nice philosophical arguments as to why functional programming is wonderful, but they tend to ignore the real world, which is stateful. Well, Perl and Visual Basic did too, around the same time frame, which is probably part of the reason why despite their horribleness they remain far more popular than Haskell or Scala. You will not be surprised to learn that when engineers have a tool at hand that hides complexity, that they often end up building very complex things!
Rust is likewise very OO in its nature. Who said everyone hates OO? I like it a lot when I need to code a relatively large piece of code. But instead I dont understand why FP suddenly became a holy grail. Please dont tell me a programmer or human can think about logic in recursive way naturally. Human thinks about concept in abstraction style not recursion. I do agree that OO is horrible when there are certain incompetent developers who code for a project for a few months without caring the design and then left.
When someone starts polluting the code base, without proper code review it becomes a spaghetti, and neither OO nor FP can save the project.
Totally missed from the article. Again, hugely important. OOP is just a tool — it is not a framework nor is it a dictate on how to do things. The problem we as developers face is we become overly focused on the tool, sometimes to the point of being fanatical. OOP came along and after awhile everything had to be OOP — even when there was no a good fit we tried to push that square peg into the round hole, expanding and squeezing the OOP specifications to try and make the tool work around the problem.
The team that has to cater to developer churn has to comply with standards to ensure continuity and cohesion in the team — while this provides necessary structure and stability to the production process it removes from it certain freedoms that stand alone developers have in terms of exploring different ways of solving a problem.
To put it another way the team developer in a conformant corporate unit has a bag with a hammer, a saw and a chisel and is asked to make a cabinet. The freelancer can use a drill, circular saw, hack saw, rasp and a bunch of other tools that allow for far more flexibility and refinement. As I said it is a trade-off.
In the same way that physicists are searching for the one unifying theory, developers and engineers are searching for the one paradigm into which any software problem will fit — and we have not found that yet. For now we mix and match what works.
There will still be those new tool that come out that many will be convinced is the tool or paradigm but the nature of the industry and the people in it is to continually search for better ways to do things and so the new things will come and go, be assimilated or forgotten.
OOP is no different. There are some important advantages that OOP gives us that cannot be ignored — it is really about how we use it in conjunction with other techniques and tools that is what is going to determine its future. I can no see any hate at all, and it would not make any sense. One might like to tell me waht all-day software in widesprad use is not kind of object-oriented? I seldom reply to opinionated articles that merely repeat old ideas and provokes discussion in an antipodean manner, but I need to point out one critical aspect missing from both sides of the debate: Virtually nobody is doing OOP today, but rather COP — Class Oriented Programming.
I cannot stress this enough. It has all become about classes and concepts created as a consequence of this. And the focus is horribly adverse towards what really matters in programming — the user. The user cares about objects, not templates of objects and the structure the engineers have designed. Fortunately there is a way out of this endless struggle. If you truly want to move from classes to objects however, follow the website link, and the user will thank you!
OOP is so succesfull for the simple reason that universe around us is full of cooperating objects. OOP is easy to comprehend and design, if someone does not over engineer it. But, in alternative universe, maybe there are function MyCarGo driver that internally destroys me and creates my new identical copy at the destination place…. But for me classes are more like useful brackets. If the long sequential task can be divided into separate subtasks I may employ the same strategy downstream.
Then the main bracket class just sequentially intantiates a bunch a number of subclasses and calls their one public function.
Of course you have interconnected systems where one change fires an event and that event is caught and processed but even then this often just means that a further task is to be sequentially be worked on. Some coders do indeed hate OOP. Good OOP is what all code should strive to look as.
Build simple modules that achieve a purpose and are trimmed clean of any unnecessary function. If anything, it will enable the developer with flexibility, to build a system that can easily be fractured and provided in its necessary parts strictly. This makes maintaining and updating the system a beautiful process. Most developers love it. So FP advocates do what people who fail at fair competition always do: go into politics. They lie. You still need good design. Interesting article that omits at least one elephant in the room: SQL.
The SQL standard had virtually no provision or requirements for OOP concepts until structured types in SQL and still today not all major vendors support that and none supports it fully, I believe. Yet its easy to think of a table as an object and a function as a method, but the two are not usually bound together, with triggers and structured types being possible exceptions. But then SQL offers a kind of declarative programming which is neither oop nor strictly imperative and not fully covered by those paradigms or the functional paradigm for that matter.
I think the question is wrong. Old procedural code did not scale and OOP promised something that did, but failed to deliver and was destroyed totally by Giuseppe Castagna decades ago as theoretically unsound and almost completely useless for any application the so-called covariance problem makes methods useless for handling any problem with two variant arguments, which is almost every interesting problem.
The question is why OOP is still taught by those that should know better and why researchers still waste time trying to invent a perpetual motion machine. The answer is probably that the other alternative, functional programming, is even more useless. The algebraic framework which has the desirable properties is over three decades old but it is very hard for even professional mathematicians to understand, and has never been modelled successfully in a programming language.
Category theory is just plain hard, and humans always take the easy way out, the path of least resistance: make a huge mess but we do not care as long as everyone else is making a mess too.
Can anybody elaborate, or redirect me to elaborations, on how concepts from OOP and FP facilitate on their ways tasks like creation, test, documentation, fix, improvement and reuse? The title is absolutely exaggerated. Where is my proof? Where is your proof? OOP is still necessary for many reasons. In some fields you just want to use plain C for the sake of simplicity. But a OOP started with Simula a language for simulation. I think one aspect is often not mentioned: the packaging of functions with data definitions.
It is this grouping into classes that allows OO languages to model the real world so easily. Keeping methods and the data they maintain as state within objects is how encapsulation encourages reusable code and prevents large classes of bugs. Take a look at what the awesome Julia language offers: multiple dispatch.
OOP is a tool just like any other programming construct. It has appropriate uses and inappropriate uses. The tool needs to be selected for the job. OOP lends great advantage to large scale tasks. It adds unnecessary complexity to simple tasks. I think this is caused by the following: 1. All of the books that promote complex OOP architectures and concepts where they have absolutely no business.
The overuse of inheritance. Developer narcissism — people who gravitate to the most complex solutions because they want to prove how smart or hip they are. OOP is valuable to be sure, but has been used in many deleterious ways. The problem identified by Joel remains the single biggest issue in software development today. However, if you are working on a small project it might not be the best choice. There are many things to consider, but variable scope can be a nightmare without the protection that OOP provides.
The textbook UML user guide from my college days summed it up best… if you want to build a dog house for your dog… just go to the hardware store, get some nails, lumber, and a few tools. Thus, authors stressed using models to identify use cases and pattern reuse. Coding is a matter of abstraction. We abstract real life objects and situations into variables and functions.
So what makes one generation of languages different from the other? Each one is a product of its time and the data abstraction needs posed by said time.
The first generation, machine code and assembly, arrived when computers were still novel and applications were more simple. The code focused on instructing the machine to automate a set of simple tasks. The second generation, C, arrived when data needs increased and applications became more complicated. C took care of most of the machine-specific details and allowed coders to focus on abstraction problem solving.
C simplified programming. The third generation, Java, arrived well in time with the computer revolution. Computer systems could already be found everywhere, and the web was really starting to take off.
OOP took a simple idea, that modularization is the easiest way to solve any given problem, and standardized that idea amongst coders. The problem was that procedural languages rendered modularization a hell of a hassle.
But the world needed modularization and its simplicity because of the ever increasing integration and reliance on computer systems. OOP then came to the rescue by spawning its own set of languages, 3rd gen languages, that easily facilitated modularization of code. It essentially made computer programming more available to the public by making it easier. Both paradigms are equally capable. OOP being the next generation in line simply made coding easier and pushed programmers towards high level abstraction.
The fourth generation, SQL, is on a whole different league of its own. The way it goes now is that we type up millions of 3rd gen lines, we add in a few thousand 4th gen lines, and if push comes to shove we throw in a few segments of 2nd gen code for optimization and compatibility with low level sysyems.
It all however must compile to 1st gen code in the end — ready to load up on RAM. I do agree with most of the comments that OOP is not hated in general. Maybe functional languages are a bit of a hype right now, and most of these do not have OOP features. Just because a lot of people leave stereotypical OOP languages does not mean they hate them. The opposite of OOP is procedural and the opposite of functional is imperative.
Scala shows that an OOP language can have functional programming for the implementation of their methods. Subtyping is a marker of OOP and inheritance is most often the implementation of this concept in a specific programming language.
Prototypes or copying from an existing object are other ways to implement subtyping. I think one of the major reasons at least in my line of work that OOP is so prevalent is that it is currently the best way to write GUIs.
I love using Qt to write my GUI. I am not sure, though, if I would like to write a library like this. Strong adherence to every single OOP principle all the time is quite tedious.
On the other hand I do hate sticking perfectly to encapsulation all the way through. And with this part of OO design principles I strongly disagree. Some OOP languages even lets you have the compiler write the setter and getter automatically and use assignment syntax to call these. So, why would you enforce them everywhere?
I have seen academic examples where you could switch out the implementation of the class entirely. However, I think this is too much overhead for the small possibility that it might happen in the future.
Interfaces are just like interfaces of electronics — we have a panel with some buttons but the details of what happens when their are pressed are hidden from the user — same happens with interfaces in oop though interfaces can have some additional meanings. As you can see OOP allows us to express code in natural way which mirrors the real world with its objects and actions.
OOP is an evolution of procedural programming — which in its turn was created to allow us express code in a more natural manner to us humans than assembly — which is designed around how the computer works, not around how we think, communicate, understand the world.
Some people seem to forget that if they ever were aware of it. Yes, it is sometimes the case that OOP programs are not easily maintainable. In my experience, that fault often stems from overuse of inheritance, as has been noted in this discussion, particularly the creation of long chains of itty-bitty classes that individually do not add much.
If a class is merely the parent of a subclass, if it is not going to be instantiated and used itself, then maybe it does not need to be in the hierarchy. OOP is a tool like any other, and can be used well or badly. Slavishly following the OOP lessons that one learned in school may not result in code that can be understood by a new generation of maintainers. Over the years, I have found that OOP helps me organize my intentions and the actions of my code, and to isolate data and functions, and all of those reduce complexity and make debugging dramatically easier.
For instance, I just finished a large, multi-year research project in which the directions of the research changed dramatically over the many months. Every time we found an answer to a question, another question arose that required some additional coding, some recoding.
Few modules remained unaltered for more than a few months at a time, but some did. The few that did were ones that represented well-understood objects, and isolated them data and function from changes in the business logic due to new requirements.
If the edit history of a class module had a year of dust on it, I considered that a real success. Not a big deal, but took more than four years to evolve to answer all the questions.
Some programmers I know would surely have used classes where 40 sufficed. Functional Programming makes a lot of assumptions about the environment it runs in; so in OOP terms, programs that are functional run inside components or encapsulated environments; on the other side, OOP can leverage a lot from FP so as to achieve functionalities that are not dependent of the state of anything.
Small linear systems allow heavy application of algorithm driven design that favors functional design, such systems however are not flexible, there is a certain tolerance in which you can stretch the input and expect a valid output. Another problem with such systems is the way they mutate as they generate knowledge about the problem they are designed to solve- although as correctly pointed in the article linear execution is the way the processor runs the code, the learning curves and the changes that come with them are non linear and not continuous- this makes the scalability of such systems poor.
Here we can see that the same person showing different behavior every time the surroundings are changed. This means polymorphism is flexible and helps developers in a number of ways. Decomposing a complex problem into smaller chunks or discrete components is a good practice. OOP is specialized in this behavior, as it breaks down your software code into bite-sized — one object at a time. The broken components can be reused in solutions to different other problems both less and more complex , or either they can be replaced by the future modules that relate to the same interface with implementations details.
A general relatable real-time scenario — at a high level, a car can be decomposed into wheels, engine, and chassis soon. Each of those components can be further broken down into even smaller atomic components like screws and bolts. This has been a guide to the Advantages of OOP. You may also look at the following articles to learn more:.
Submit Next Question. By signing up, you agree to our Terms of Use and Privacy Policy. Forgot Password? This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy.
By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy. Popular Course in this category.
0コメント