<?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: EliteSalad</title>
    <description>The latest articles on DEV Community by EliteSalad (@xavieroliver).</description>
    <link>https://dev.to/xavieroliver</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%2F760084%2F0aaa6b48-edb4-48c7-9106-d73e46a281e0.jpeg</url>
      <title>DEV Community: EliteSalad</title>
      <link>https://dev.to/xavieroliver</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/xavieroliver"/>
    <language>en</language>
    <item>
      <title>Behavioural Patterns: Strategy Pattern</title>
      <dc:creator>EliteSalad</dc:creator>
      <pubDate>Sun, 28 Nov 2021 23:46:39 +0000</pubDate>
      <link>https://dev.to/xavieroliver/behavioural-patterns-strategy-pattern-4h0d</link>
      <guid>https://dev.to/xavieroliver/behavioural-patterns-strategy-pattern-4h0d</guid>
      <description>&lt;p&gt;Strategy pattern defines a family of algorithms Defines each one of them and makes them interchangeable. Strategy lets the algorithm vary independently from the clients that use it.&lt;/p&gt;

&lt;p&gt;Inheritance is a pretty basic object-oriented technique that allows subclasses created from already existing classes to use functions and variables from their parent class. This easily allows behaviors to be similar and means code can be reused. There are however circumstances where an inheritance will in fact create more duplicate code than can easily be managed to bring with it all the folly of having copy-paste code from one section to another. This can occur because when inherited functions can be inherited down easily but they cannot be inherited across. Here is an example of when code would be duplicated under inheritance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lXjodE9D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p2l4uh5z5mkuy4xszl2j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lXjodE9D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p2l4uh5z5mkuy4xszl2j.png" alt="Image description" width="337" height="237"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above UML 2 subclasses are using the same Fight function and two are also utilizing the same Eat function. Despite that, on implementation, those repeat functions will have to be written out in full twice or even more if another class shares that functionality. There is no way for the one function to be used by one of its sister classes,  but strategy patterns can circumnavigate this dilemma.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--INs46a0k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/berju1uimjw8qpq8xpgt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--INs46a0k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/berju1uimjw8qpq8xpgt.png" alt="Image description" width="416" height="178"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A strategy pattern takes functionality away from the function within the class instead of requiring an interface class for that function to be created which can then act as a directory to select a class for them. Now that the interface class exists it can assign completely different classes even ones unrelated to the base class with the exact same functionality if required. This is the logic applied to the first UML diagram&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FKwUBrB7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1zxntucw3xddw5gxa6ui.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FKwUBrB7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1zxntucw3xddw5gxa6ui.png" alt="Image description" width="683" height="243"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is possible to take this one step further completely foregoing inheritance itself and instead establishing all parts of the base class as interfaces. This would then mean the subclass would instead be a collection of the correct interfaces instead of one that inherited the correct functionality and had overridden other parts. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WXDRtwEt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0e2h4yl7au8fzpbt5lkb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WXDRtwEt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0e2h4yl7au8fzpbt5lkb.png" alt="Image description" width="605" height="299"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This complete lack of inheritance means no class in this model 'is a' form of another class and instead it is a group of classes that 'has a' bunch of other classes creating a spider web of links as opposed to a tree of inheritance. This method probably shouldn't be the default with simple projects or small use cases but it definitely has earned the right o be as prolific as inheritance in my opinion. Sandi Metz argues the benefits of composition over inheritance in her Nothing is something talk on the null object pattern.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>productivity</category>
      <category>codequality</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Moving Objects in Unity The Right Way</title>
      <dc:creator>EliteSalad</dc:creator>
      <pubDate>Sun, 28 Nov 2021 23:05:40 +0000</pubDate>
      <link>https://dev.to/xavieroliver/moving-objects-in-unity-the-right-way-3jkb</link>
      <guid>https://dev.to/xavieroliver/moving-objects-in-unity-the-right-way-3jkb</guid>
      <description>&lt;h2&gt;
  
  
  Physics based
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Rigidbody SetVelocity
&lt;/h3&gt;

&lt;p&gt;rb.velocity = transform.forward;&lt;br&gt;
Once velocity is set provided there is no drag object will maintain pace until collision.&lt;br&gt;
Great for launching an object with a speed independent of its mass&lt;/p&gt;

&lt;h3&gt;
  
  
  Rigidbody MovePosition
&lt;/h3&gt;

&lt;p&gt;rb.MovePosition(transform.position + (transform.forward * Time.deltaTime));&lt;br&gt;
Only physics based way to move a kinematic object&lt;br&gt;
Stable Way to move a rigidbody object without manipulating the physics of the object just the position.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rigidbody AddForce
&lt;/h3&gt;

&lt;p&gt;rb.AddForce(transform.foward * Time.deltaTime );&lt;br&gt;
Every frame force will be added leading to acceleration up to infinity provided drag is 0.&lt;br&gt;
Allows for specific force modes to be inserted such as Start, Impulse, Acceleration, Force, and Velocity Change. These can all change the behavior of how that particular force is applied to the object.&lt;/p&gt;

&lt;h2&gt;
  
  
  Position Based
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Transform Translate
&lt;/h3&gt;

&lt;p&gt;transform.Translate(Vector3.foward * Time.deltaTime);&lt;br&gt;
Gives an amount of space to move each frame&lt;br&gt;
Great for animating &lt;br&gt;
Can move kinematic objects&lt;/p&gt;

&lt;h3&gt;
  
  
  Transform Set Position
&lt;/h3&gt;

&lt;p&gt;transform.position += transform.forward * Time.deltaTime;&lt;br&gt;
Giving new position to move every frame&lt;br&gt;
Great for animating &lt;br&gt;
Can move kinematic objects&lt;/p&gt;

&lt;p&gt;Because movement operations through transform happen asynchronously when moving through or next to an object with a collider on the object may bounce or stutter as it tries to continue in the desired direction. This is because it successfully moves before being rejected back out by the physics of the collider. Because of this using these functions on an object that is meant to touch another object in some way is not recommended. &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>unity3d</category>
      <category>physics</category>
    </item>
  </channel>
</rss>
