<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: michaelyatco</title>
    <description>The latest articles on DEV Community by michaelyatco (@michaelyatco).</description>
    <link>https://dev.to/michaelyatco</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F25853%2F33450b29-8470-47a6-802c-16c003606b52.jpg</url>
      <title>DEV Community: michaelyatco</title>
      <link>https://dev.to/michaelyatco</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/michaelyatco"/>
    <language>en</language>
    <item>
      <title>It’s About Sending a Message - A Focus on Scalable Object OrientedÂ Design</title>
      <dc:creator>michaelyatco</dc:creator>
      <pubDate>Fri, 14 Jul 2017 21:38:17 +0000</pubDate>
      <link>https://dev.to/michaelyatco/its-about-sending-a-message---a-focus-on-scalable-object-orienteddesign</link>
      <guid>https://dev.to/michaelyatco/its-about-sending-a-message---a-focus-on-scalable-object-orienteddesign</guid>
      <description>

&lt;p&gt;It’s one thing to learn how to create an application using an object-oriented framework like Ruby on Rails.&lt;/p&gt;

&lt;p&gt;It’s quite another to know how to create an application well, and by that, I mean that the code within an application is &lt;em&gt;scalable&lt;/em&gt;, &lt;em&gt;reusable&lt;/em&gt;, and &lt;em&gt;flexible to change with minimal cost&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F7o96zc3p7xfc873xam74.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F7o96zc3p7xfc873xam74.png" alt="alt-text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When constructing simple apps, developers new to OOD, myself once included, tend to have a &lt;code&gt;class-based perspective&lt;/code&gt;. &lt;strong&gt;“I know I need this class, what should it do?”&lt;/strong&gt; is the foundation of this mindset.&lt;/p&gt;

&lt;p&gt;Adopting a &lt;code&gt;message-based perspective&lt;/code&gt;, however, changes the question to, &lt;strong&gt;“I need to send this message, who should respond to it?”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As a concrete example, if I were to create an app for a cycling store that arranged bike trips, my initial programming might create a &lt;code&gt;Trip class&lt;/code&gt; that responded to a customer inputting the date of the trip, the difficulty of the course, and if they needed a bike, and if so, what type of bike and to check if that bike was ready to ride.&lt;/p&gt;

&lt;p&gt;Instead of cramming many responsibilities into a single class, focus on the message, “Should &lt;code&gt;Trip class&lt;/code&gt; be receiving the message about the availability of bicycles? Should &lt;code&gt;Trip class&lt;/code&gt; be receiving the message about the condition of the bicycle?” Now the idea of creating a &lt;code&gt;Bicycle class&lt;/code&gt; or a &lt;code&gt;Mechanic class&lt;/code&gt; becomes a logical choice.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Having a message-based perspective in OOD doesn’t make you anti-class, rather it allows you to create the appropriate amount of single-responsibility classes based on the messages passed betweenÂ objects.&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;It’s important to delegate responsibilities in OOD. If your &lt;code&gt;Trip class&lt;/code&gt; has methods for having a bicycle’s frame cleaned by the mechanic, tires pumped by the mechanic, chain lubed by the mechanic, and brakes checked by the mechanic, you’ve overloaded your &lt;code&gt;Trip class&lt;/code&gt; with dependencies.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F6iec1o3hh3h33tey3xm5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F6iec1o3hh3h33tey3xm5.png" alt="alt-text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Trip class&lt;/code&gt; is dictating how your &lt;code&gt;Mechanic class&lt;/code&gt; should act. The message Trip is telling Mechanic here is &lt;strong&gt;“I know what I want and I know how you do it.”&lt;/strong&gt; Not only that, if &lt;code&gt;Mechanic class&lt;/code&gt; were to ever change its preparation methods, &lt;code&gt;Trip class&lt;/code&gt; would break.&lt;/p&gt;




&lt;p&gt;A key concept in OOD is to keep the messages as abstract as possible through “Duck Typing”. For example, instead of writing such concrete methods crammed into a single &lt;code&gt;Trip class&lt;/code&gt;, find the overarching simple message, in this case, &lt;strong&gt;“I want to prepare a trip.”&lt;/strong&gt; From there, objects (i.e. classes) can collaborate without binding themselves to context and new objects can be introduced without re-tweaking every class created.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F47gafwp9dpoururr4m82.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F47gafwp9dpoururr4m82.png" alt="alt-text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As opposed to the first example, this example has &lt;code&gt;Trip class&lt;/code&gt; telling every other class &lt;strong&gt;“I know what I want and I trust you to do your part.”&lt;/strong&gt; This is a key component in OOD as there is more room for growth and for change.&lt;/p&gt;

&lt;p&gt;If this example looks familiar, it’s because it was adapted from Sandi Metz’s work &lt;em&gt;Practical Object-Oriented Design in Rubyâ€Š–â€ŠAn Agile Primer&lt;/em&gt;. I read this book outside of my usual regimen of coding exercises, algorithms, and Git commits because I wanted to move beyond focusing on the quantity of my coding. Rather my focus now is on the quality of my coding; coding that is &lt;em&gt;scalable&lt;/em&gt;, &lt;em&gt;reusable&lt;/em&gt;, and &lt;em&gt;flexible to change&lt;/em&gt;â€Š–â€Šcoding that adheres faithfully to object oriented design.&lt;/p&gt;

</description>
      <category>oop</category>
      <category>rails</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Hi, I'm michaelyatco</title>
      <dc:creator>michaelyatco</dc:creator>
      <pubDate>Fri, 14 Jul 2017 20:54:48 +0000</pubDate>
      <link>https://dev.to/michaelyatco/hi-im-michaelyatco</link>
      <guid>https://dev.to/michaelyatco/hi-im-michaelyatco</guid>
      <description>&lt;p&gt;I have been coding for 1 year.&lt;/p&gt;

&lt;p&gt;You can find me on GitHub as &lt;a href="https://github.com/michaelyatco" rel="noopener noreferrer"&gt;michaelyatco&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I live in the Lower East Side.&lt;/p&gt;

&lt;p&gt;I work for The Difference Engine.&lt;/p&gt;

&lt;p&gt;I mostly program in these languages: Ruby on Rails, JavaScript, Java, Python, AngularJS, HTML5/CSS3.&lt;/p&gt;

&lt;p&gt;I am currently learning more about Java and Python.&lt;/p&gt;

&lt;p&gt;Nice to meet you.&lt;/p&gt;

</description>
      <category>introduction</category>
    </item>
  </channel>
</rss>
