如何练习更好的面向对象编程? [英] How can I practice better object-oriented programming?

查看:57
本文介绍了如何练习更好的面向对象编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

多年来,我一直在使用面向对象的语言进行编程,但是秘密地看了我的同事羡慕不已的一些事情.他们中的许多人似乎都有一些我没有的内在的OO本能-无论我多么努力.我已经阅读了所有有关OO的好书,但似乎仍然无法破解.我觉得这个家伙付出了110%的职业足球运动员的心,却只是没有天赋才能做到这一点.我很茫然,想换职业-我该怎么办?

I have been programming in object-oriented languages for years now but secretly I look at some of the things my colleagues do with envy. A lot of them seem to have some inner OO instinct that I don't have - no matter how hard I try. I've read all the good books on OO but still can't seem to crack it. I feel like the guy who gave 110% to be a professional footballer but just didn't have the natural talent to make it. I'm at a loss and thinking of switching careers - what should do I?

推荐答案

我要说的是,较少关注OO编程,而更关注OO 设计.拿起纸和铅笔(或者可能是UML建模工具),然后离开屏幕.

I would say focus less on the OO programming and focus more on the OO design. Grab a paper and a pencil (or maybe a UML modelling tool), and get away from the screen.

通过练习如何设计系统,您将开始对对象关系有一种自然的感觉.代码只是设计的副产品.绘制图表并以纯非代码形式对应用程序建模.有什么关系?您的模型如何相互作用?甚至不用考虑代码.

By practicing how to design a system, you'll start to get a natural feel for object relationships. Code is just a by-product of design. Draw diagrams and model your application in a purely non-code form. What are the relationships? How do your models interact? Don't even think about the code.

一旦您花了很多时间进行设计,然后将其转换为代码.您会惊讶于一个好的OO设计可以这么快地编写代码.

Once you've spent time designing... then translate it to code. You'll be surprised at just how quickly the code can be written from a good OO design.

经过大量的设计实践,您将开始看到可以模块化或抽象化的公共区域,并且您的设计和代码都将得到改善.

After a lot of design practice, you'll start seeing common areas that can be modularized or abstracted out, and you'll see an improvement in both your designs and your code.

这篇关于如何练习更好的面向对象编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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