4 Ways to Learn Object-Oriented Design
Tags: design, java, python, javascript
Published: 2020-02-23 15:10:33

<!-- wp:image {"id":5073,"align":"center","width":225,"height":268} -->
<div class="wp-block-image"><figure class="aligncenter is-resized"><img src="https://tenmilesquare.com/wp-content/uploads/2020/01/sketch-4748895_640.jpg" alt="" class="wp-image-5073" width="225" height="268"/></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Looking back over 2019 I realized I've had the privilege to work on a diverse set of software projects:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>Architecting and coding an Enterprise Transform and Load (ETL) project in Python and Django</li><li>Building an SFTP platform using AWS lambda, Node, and Vue</li><li>Adding major features and refactoring a long-term enterprise Java project </li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>While reviewing these projects one common thing stuck out as to why these projects were considered a success, it was due to their object-oriented design.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>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 <a href="https://tenmilesquare.com/data-transform-and-load-overview/">ETL pipeline to use a canonical,</a> 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.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This got me thinking about how I learned object-oriented design. Some of the answers are obvious, but others are less so. I want to share these approaches with you.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>1. Courses</h2>
<!-- /wp:heading -->

<!-- wp:image {"id":5072,"align":"center","width":355,"height":236} -->
<div class="wp-block-image"><figure class="aligncenter is-resized"><img src="https://tenmilesquare.com/wp-content/uploads/2020/01/woman-2701154_640.jpg" alt="" class="wp-image-5072" width="355" height="236"/></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>My earliest object-oriented design training was from taking an employer-sponsored training course with Training Hott. The course covered the most common <a href="http://www.blackwasp.co.uk/gofpatterns.aspx">Gang of Four</a> 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.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Today there are a ton of different online resources for learning design patterns. Going the online route is cheaper than live training and often is more hands-on, but requires self-discipline to finish the course. Lastly, the barrier to entry for creating an online course is low and sometimes the quality of the course may suffer.</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li><a href="https://www.udemy.com/courses/search/?src=ukw&amp;q=software%20design">Udemy</a></li><li><a href="https://www.coursera.org/courses?query=design%20patterns">Coursera</a></li><li><a href="https://www.linkedin.com/learning/search?keywords=design%20patterns">Linkedin Learning</a></li></ul>
<!-- /wp:list -->

<!-- wp:heading -->
<h2>2. Books</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>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, <a href="https://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=asc_df_0201633612/?tag=hyprod-20&amp;linkCode=df0&amp;hvadid=312280575053&amp;hvpos=1o8&amp;hvnetw=g&amp;hvrand=6962496824570411812&amp;hvpone=&amp;hvptwo=&amp;hvqmt=&amp;hvdev=c&amp;hvdvcmdl=&amp;hvlocint=&amp;hvlocphy=9011972&amp;hvtargid=aud-801381245258:pla-395340045790&amp;psc=1">Design Patterns: Elements of Reusable Object-Oriented Software</a>. However, it can be a tough read, especially for beginners. </p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5067,"align":"center","width":457,"height":347} -->
<div class="wp-block-image"><figure class="aligncenter is-resized"><img src="https://tenmilesquare.com/wp-content/uploads/2020/01/Screen-Shot-2020-01-26-at-2.36.41-PM-1024x780.png" alt="" class="wp-image-5067" width="457" height="347"/><figcaption>Taken from:<a href="https://martinfowler.com/bliki/GangOfFour.html"> https://martinfowler.com/bliki/GangOfFour.html</a></figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>In my experience, I found the Head First books an excellent place to start or to refresh yourself. They are broken down in digestible chunks with coding and thought exercises at the end of each section. Sort of like a <em>Highlights for Coders.</em> Two great books to start with are</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li><a href="https://www.amazon.com/Head-First-Design-Patterns-Brain-Friendly/dp/0596007124">Head First Design Patterns</a></li><li><a href="https://www.amazon.com/Head-First-Object-Oriented-Analysis-Design/dp/0596008678">Head First Object-Oriented Analysis and Design</a></li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>O'Reilly also publishes great books on the subject and often teaches the subjects by building a sample application with the concepts.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>3. Reading and Mimicking Code</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>One of my favorite methods of learning new design patterns is digging into the source code of my favorite frameworks and libraries. The Spring Framework has taught me more about design than any course or book. This method may be difficult for the beginner as some frameworks, such as Spring, are highly abstracted and it can be difficult to understand why classes are broken apart. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>A great way to begin to dive into an abstract framework is to try and extend a portion of the framework. Often frameworks are set up to allow users to extend interfaces and abstracts in order to modify the behavior of a particular component. The Spring documentation is very detailed and often will walk the reader through the how and why of a component's design.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5069,"align":"center","width":207,"height":207} -->
<div class="wp-block-image"><figure class="aligncenter is-resized"><img src="https://tenmilesquare.com/wp-content/uploads/2020/01/gaiman.jpg" alt="" class="wp-image-5069" width="207" height="207"/><figcaption>“Most of us find our own voices only after we’ve sounded like a lot of other people.”<br><br>―&nbsp;<strong>Neil Gaiman﻿</strong></figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Another way is to read and extend the code of your team. One of my biggest jump in understanding how to create reusable components was reading and mimicking the code of the smartest people on my team. Seeing how and why code is abstracted and asking them questions about the code will often give you insight into a different way of thinking and designing. </p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>4. Refactoring</h2>
<!-- /wp:heading -->

<!-- wp:image {"id":5071,"align":"center"} -->
<div class="wp-block-image"><figure class="aligncenter"><img src="https://tenmilesquare.com/wp-content/uploads/2020/01/refactoring-i1.png" alt="" class="wp-image-5071"/></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Picking up a refactoring task or refactoring your own code before you commit is a great way to improve your understanding of design patterns. As you read the code you can begin to see where code is duplicated, confusing, or hard to test. Refactoring causes you to remove yourself from the actual code and think abstractly about how it fits into the application. Asking questions such as</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>When this is refactored how can I verify it behaves the same way?</li><li>What tests are missing from the original code?</li><li>How can I componentize the code?</li><li>How can I eliminate multiple or nest ifs and loops?</li><li>How can I combine two methods or classes?</li><li>How can I test a particular piece a logic inside a long method or function with minimum set up?</li><li>If I was to support this code 3 years what would make this code easier to support?</li><li>If the requirements were to change or the business wanted to change the behavior, how can I make it configurable?</li></ul>
<!-- /wp:list -->

<!-- wp:heading -->
<h2>Conclusion</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>I believe that proper design allows developers to easily maintain, extend, change, and test code and is often overlooked in many components. On top of becoming a better coder and creating better code, I believe you also begin to appreciate coding aesthetically and get more satisfaction from the work.</p>
<!-- /wp:paragraph -->