Write a code that endures endless business requirements: Part-3 On Designing Software Properly!
Tags: programming
Published: 2020-03-12 21:19:30

<!-- wp:paragraph -->
<p>Hello everyone!</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>We've been spending a lot of time in the last blog posts
understanding <a href="https://www.smartercode.io/19-why-you-should-aggressively-invest-in-your-coding-skills/">what
bad code is</a>, how to <a href="https://www.smartercode.io/write-a-code-that-endures-business-endless-requirements-part-1-on-code-quality-metrics/">objectively
measure it</a>, and even more, how to <a href="https://www.smartercode.io/write-a-code-that-endures-endless-business-requirements-part-1-on-code-refactoring/">refactor
a committed crime</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>And now, the time comes to understand how we can brilliantly
craft a well-designed (hopefully?) <a href="https://en.wikipedia.org/wiki/Greenfield_project">greenfield project</a> that
is easy to maintain, to read, and to extend in the future.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The purpose of software engineering is to control complexity
not to create it</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>When developing software, the complexity lies in many areas,
such as:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>Understanding the business
requirements and using unified communication language. That is, what are the different
players we have across various business domains? What is, do our customers
speak? Why team A and team B have different names to the same things? </li><li>How are we going to
architect and separate different application layers? How should each project
reference the other?</li><li>How to make our code more
object-oriented, clean, and reusable?</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>To resolve the previously mentioned challenges, we are going
to discuss three things that aim to face them, respectively:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>Understanding the
application domain using Domain-Driven Design</li><li>Understanding how to
architect and distinguish different parts of the application</li><li>Doing the actual work and
crafting a well-designed code based on best practices</li></ul>
<!-- /wp:list -->

<!-- wp:heading {"level":1} -->
<h1>Welcome to domain-driven design</h1>
<!-- /wp:heading -->

<!-- wp:image {"id":502,"width":530,"height":308,"sizeSlug":"large"} -->
<figure class="wp-block-image size-large is-resized"><img src="https://i1.wp.com/www.smartercode.io/wp-content/uploads/2020/03/DDDpng.png?fit=1024%2C595&amp;ssl=1" alt="" class="wp-image-502" width="530" height="308"/><figcaption> Figure 1 DDD bridges the business domain jargon and technology domain jargon by introducing ubiquitous language </figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Briding the business jargon and technical jargon are already
discussed in a well-established methodology called Domain-Driven Design (DDD).
In his book (<a href="https://www.smartercode.io/domain-driven-design-book">Domain-Driven
Design: Tackling Complexity in the Heart of Software</a>), Eric Evans defines
Domain-Driven Design as a software approach to <em>complex</em> needs by
connecting the implementation to an <em>evolving</em> model. The words <strong>complex</strong>
and <strong>evolving</strong> are vital traits that we see in our daily software
requirements.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The main objective of DDD is to set the focus on the domain
logic, which is considered the core logic. It also aims to base the software
design on the business domain. And most importantly, it seeks to bridge the gap
between the business domain jargon and the technology domain jargon by introducing
ubiquitous language. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If you feel too lazy to read Eric Evan's book, I would like
to point you to <a href="https://app.pluralsight.com/library/courses/domain-driven-design-fundamentals">this</a>
fantastic Pluralsight course by Steve Smith and Julie Lerman.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":1} -->
<h1>Architecting Your Application</h1>
<!-- /wp:heading -->

<!-- wp:image {"align":"center","id":501,"width":505,"height":381,"sizeSlug":"large"} -->
<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img src="https://www.smartercode.io/wp-content/uploads/2020/03/2010s-layered-architecture.png" alt="" class="wp-image-501" width="505" height="381"/><figcaption> Figure 2 A diagram showing an example of layered software architecture </figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Another aspect that profoundly influences the
maintainability and extendability of our software solution is how do we
architect different decoupled layers of our application.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>By saying different layers, I mean different parts of
the software that have particular responsibilities. For example, the <strong>UI
layer</strong> is used to designate what the user sees (Web Pages, Desktop Forms, or
Mobile App). In contrast, the <strong>Infrastructure layer</strong> is used to designated
external dependencies to the software such as File Systems and Drivers. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>You will hear the term <strong>abstractions</strong> to refer to the
fact that a specific piece of the software introduces a general level of
separation that makes it possible to replace it with other components. For
example, when we say that the user interface should be abstracted, that means
it should be easy to replace a web page interface with a mobile interface without
much changes to other parts of the code. The antonym of <strong>abstract </strong>is<strong>
concrete </strong>and is used to describe a piece of software that is highly
specialized in doing only one thing.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>A well-architected software is <strong>abstracted</strong> just
enough to be general to all foreseen business scenarios. Yet, it is <strong>concrete</strong>
enough to be understandable and fast to develop. An excellent architect is
always striking a balance between abstraction and concretion to develop the
software according to the business strategy and forecasted product demands.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://app.pluralsight.com/library/courses/architecting-applications-dotnet/table-of-contents">Architecting
Applications for the Real World in .NET</a> is an excellent course by Cory
House that teaches how to think about your application layering. He discusses
different architectural styles and presents common software layers. I would
highly recommend it.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":1} -->
<h1>Writing well-designed code</h1>
<!-- /wp:heading -->

<!-- wp:image {"align":"center","id":500,"width":425,"height":327,"sizeSlug":"large"} -->
<div class="wp-block-image"><figure class="aligncenter size-large is-resized"><img src="https://www.smartercode.io/wp-content/uploads/2020/03/java-oops.png" alt="" class="wp-image-500" width="425" height="327"/><figcaption> Figure 3 Components of OOP </figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>After we knew how to understand the business jargon and map
it to the technical jargon using DDD and how to architect our application to
different layers, now comes the time to get into the details and learn how to design
our code correctly. And by code, I do not mean application layers but
rather how to ensure proper OOP (object-oriented programming) and, most
importantly, adequate OOD (object-oriented design).</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>I would recommend two courses by Zoran Horvat to develop
object programming skills</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://app.pluralsight.com/library/courses/c-sharp-code-more-object-oriented/table-of-contents">Making
Your C# Code More Object-oriented by Zoran Horvat</a></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://www.smartercode.io/master-iterative-oop">Mastering
Iterative Object-oriented Development in C#</a></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>That is it! This concludes our series on Code Quality, tell
me what do you think!</p>
<!-- /wp:paragraph -->