OOP的实际用途 [英] Practical uses of OOP

查看:102
本文介绍了OOP的实际用途的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近与不喜欢 OOP 的同事进行了辩论. .他说的话引起了我的注意:

I recently had a debate with a colleague who is not a fan of OOP. What took my attention was what he said:

在对象中进行编码的目的是什么?如果可以重用,那么我可以创建一个库并调用执行任何任务所需的任何函数.我是否需要这些多态性,继承,接口,模式的概念还是什么?"

"What's the point of doing my coding in objects? If it's reuse then I can just create a library and call whatever functions I need for whatever task is at hand. Do I need these concepts of polymorphism, inheritance, interfaces, patterns or whatever?"

我们在一家小公司中,为电子商务网站和房地产开发小型项目.

We are in a small company developing small projects for e-commerce sites and real estate.

如何在日常,真实世界"设置中利用OOP?还是OOP真的是要解决复杂的问题,而不是为了日常"开发?

How can I take advantage of OOP in an "everyday, real-world" setup? Or was OOP really meant to solve complex problems and not intended for "everyday" development?

推荐答案

关于OOP的好处来自将一组数据绑定到一组行为.

The good things about OOP come from tying a set of data to a set of behaviors.

因此,如果您需要对一组相关的数据执行许多相关的操作,则可以编写对结构进行操作的许多函数,也可以使用一个对象.

So, if you need to do many related operations on a related set of data, you can write many functions that operate on a struct, or you can use an object.

对象以继承的形式为您提供了一些代码重用帮助.

Objects give you some code reuse help in the form of inheritance.

IME,使用具有一组已知的属性和方法的对象更容易,因为该对象将保留一组复杂的结构以及对其执行操作的功能.

IME, it is easier to work with an object with a known set of attributes and methods that it is to keep a set of complex structs and the functions that operate on them.

有些人会继续介绍继承和多态性.这些都是有价值的,但OOP的真正价值(我认为)来自于它封装数据并将其与行为相关联的好方法.

Some people will go on about inheritance and polymorphism. These are valuable, but the real value in OOP (in my opinion) comes from the nice way it encapsulates and associates data with behaviors.

您应该在项目中使用OOP吗?这取决于您的语言对OOP的支持程度.这取决于您需要解决的问题的类型.

Should you use OOP on your projects? That depends on how well your language supports OOP. That depends on the types of problems you need to solve.

但是,如果您在做小型网站,那么您仍然在谈论足够的复杂性,如果在开发语言的适当支持下,我将使用OOP设计.

But, if you are doing small websites, you are still talking about enough complexity that I would use OOP design given proper support in the development language.

这篇关于OOP的实际用途的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆