开发者

What is the best Pro OOP argument? [closed]

开发者 https://www.devze.com 2022-12-21 10:31 出处:网络
Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing
Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 8 years ago.

Improve this question

I am trying to get a couple team-members on to the OOP mindset, who currently think in terms of procedural programming.

However I am having a hard time putting into terms the "why" all this is good, and "why" they should want to benefit from it.

They use a different language than I do, and I am lacking the communication skills to explain this to them in 开发者_Go百科a way that makes them "want" to learn the OOP way of doing things.

What are some good language independent books, articles, or arguments anyone can give or point to?


OOP is good for a multi-developer team because it easily allows abstraction, encapsulation, inheritance and polymorphism. These are the big buzz words of OOP and they are the big buzz words for good reasons.

Abstraction: Allows other members of your team to use code that you write without having to understand the implementation details. This reduces the amount of necessary communication. Think of The Mythical Man Month wherein it is detailed that communication is one of the highest costs facing a development team.

Encapsulation: Allows you to change your implementation details without impacting users of your code. As such, it reduces code maintenance costs.

Inheritance: Allows your team to reuse and extend your implementations with reduced costs.

Polymorphism: Allows your team to use different implementations of a given abstraction. If your team is writing code to read and parse data from a Stream, because of polymorphism it can now work with FileStreams, MemoryStreams and PigeonStreams seamlessly and with significantly reduced costs.

OOP is not a holy grail. It is inappropriate for some teams because the costs of using it could be higher than the costs of not using it. For example, if you try to design for polymorphism but never have multiple implementations of a given abstraction then you have probably increased your costs.


Always give examples.

Take a bit of their code you think is bad. Re-write it to be better. Explain why it is better. Your colleagues will either agree or disagree.

Nobody uses (or should use) techniques because they're good techniques, they (should) use them because they produce good results. The advantages of very simple use of classes and objects are usually fairly easy to see, for instance when you have an array of objects with n properties instead of n arrays, one for each field you care about, and so on.


Comparing procedural to OOP, the biggest winner by far is encapsulation. OOP doesn't mean that you get encapsulation automatically, but the process of doing it is free compared with procedural code.


Abstraction helps manage the complexity of an application: only the information that's required is exposed.

There are many ways to go about this: OOP is not the only discipline to promote this strategy.

Of course, it is not because one claims to do OOP that one builds an application without abundant "abstraction leaks" thereby defeating the strategy...


I have a bit strange thought. I don't know but there probably some areas exist where OOP is unnecessary or even bad (very-very IMHO: javascript programming).

You and your team probably work in one of these areas. In other case you'd failed many years ago due to teams which use oop and all its benefits (like different frameworks, UML and so on) would simply do their job more efficiently.

I mean that if you still work well without oop then, maybe, just leave it.


The killer phrase: With OOP you can model the world "as it is" *cough*.


OOP didn't make sense to me until I was working on an application that connected to two different databases. I needed a function called getEmployeeName() for both databases. I decided to create two objects, one for each database, to encapsulate the functions that ran against each one (there were no functions that ran against both simultaneously). Not the epitomy of OOP, but a good start for me.

Most of my code is still procedural, but I'm more aware of situations where objects would make sense in my code. I'm not of the mindset that everything needs to be one way or the other.


Re-use of existing code through hierarchies.


The killer argument is IMHO that it takes much less time to re-design your code. Here is a similar question explaining why.


Having the ability to pass an entire object around that has a bunch of methods/functions you can call using that object. For example, let's say you have want to pass a message around you only need to pass one object and everyone who gets that object will have access to all it's functions.

Also, you can declare some objects' functions as public and some as private. There is also the concept of a friend function where only objects that are related through OO hierarchies have access to their friend's functions.

Objects help keep functions near the data they use and encapsulates it all into one entity that can be easily passed around.

0

精彩评论

暂无评论...
验证码 换一张
取 消