学习面向对象设计的4种方法

学习面向对象设计的4种方法

回顾2019年,我意识到我有幸从事各种软件项目:

  • 用Python和Django设计和编码企业转换和加载(ETL)项目使用AWS Lambda,Node和Vue构建SFTP平台添加主要功能并重构长期的企业Java项目

在回顾这些项目时,有一个共同的原因是为什么这些项目被认为是成功的,这归因于它们的面向对象设计。

A key feature of each of these projects was the loose nature of the specific requirements and how details of inputs and behaviors would change as we learned more about the domain. Having a good design made making changes and testing a breeze. For example, by designing the ETL pipeline to use a canonical, a requirement change in the Python ETL project that should have taken a week to implement could be made and tested in less than a day.

这让我开始思考如何学习面向对象的设计。 一些答案是显而易见的,而其他答案则并非如此。 我想与您分享这些方法。

1.课程

学习面向对象设计的4种方法

My earliest object-oriented design training was from taking an employer-sponsored training course with Training Hott. The course covered the most common Gang of Four design patterns. It went on to teach how to organize a set of requirements into components and analyze them to see what design patterns could be used to build an application. To be honest, I don't remember much from this course, as I didn't have much opportunity to use the techniques and patterns in my daily job.

如今,有大量不同的在线资源可用于学习设计模式。 使用在线路线比现场培训便宜,并且通常动手操作,但需要自律才能完成课程。 最后,创建在线课程的入门门槛很低,有时会影响课程质量。

2.书籍

Another obvious way of learning object-oriented design is from books. Books are not only a great way to learn, but make great reference material when you've forgotten details and need a reminder. In my opinion, the secret of using books is to understand how the material is going to be presented and how you learn. The canonical design patterns book is the Gang of Four book, Design Patterns: Elements of Reusable Object-Oriented Software. However, it can be a tough read, especially for beginners.

学习面向对象设计的4种方法
Taken from: https://martinfowler.com/bliki/GangOfFour.html

根据我的经验,我发现Head First书籍是您入门或自我刷新的绝佳场所。 在每个部分的末尾,通过编码和思想练习将它们分解为可消化的块。 有点像编码员要闻。开始的两本好书是

O'Reilly还出版了有关该主题的精彩书籍,并经常通过构建包含这些概念的示例应用程序来教这些主题。

3.阅读和模仿代码

我最喜欢的学习新设计模式的方法之一是挖掘我最喜欢的框架和库的源代码。 Spring框架比任何课程或书都教会了我更多关于设计的知识。 对于初学者而言,此方法可能很困难,因为诸如Spring之类的某些框架已高度抽象,并且可能难以理解为什么将类分开。

开始深入抽象框架的一种好方法是尝试扩展框架的一部分。 通常会设置框架以允许用户扩展接口和摘要,以修改特定组件的行为。 Spring文档非常详细,通常会引导读者了解组件设计的方式和原因。

学习面向对象设计的4种方法
“Most of us find our own voices only after we’ve sounded like a lot of other people.”

― Neil Gaiman

另一种方法是阅读和扩展团队代码。 在理解如何创建可重用组件方面,我最大的进步之一就是阅读并模仿了我们团队中最聪明的人的代码。 了解如何抽象代码以及为什么抽象它们,并向他们询问有关代码的问题,通常可以使您洞悉不同的思维和设计方式。

4.重构

学习面向对象设计的4种方法

在提交之前选择一个重构任务或重构自己的代码是提高对设计模式的理解的好方法。 阅读代码时,您可以开始查看代码在哪里重复,混乱或难以测试。 重构会使您从实际代码中移开,然后抽象地考虑它如何适合应用程序。 提出诸如

  • 重构后,如何验证其行为相同?原始代码缺少哪些测试?如何将代码组成组件?如何消除多个或嵌套的if和循环?如何合并两个方法或类?如何以最少的设置在长方法或函数内部测试特定部分的逻辑?如果我要支持此代码3年,什么会使该代码更易于支持?如果要更改需求或企业想要更改行为,我如何使其可配置?

结论

我相信适当的设计可使开发人员轻松维护,扩展,更改和测试代码,并且在许多组件中经常被忽略。 相信除了成为更好的编码器和创建更好的代码之外,我相信您也开始欣赏美学上的编码,并从工作中获得更多的满意。

from: https://dev.to//ryboflavin42/4-ways-to-learn-object-oriented-design-4c1e