<?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: oleg-melnic</title>
    <description>The latest articles on DEV Community by oleg-melnic (@olegmelnic).</description>
    <link>https://dev.to/olegmelnic</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%2F546056%2F8f5bf975-a8ad-466a-b8bc-a8966ad804e6.jpeg</url>
      <title>DEV Community: oleg-melnic</title>
      <link>https://dev.to/olegmelnic</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/olegmelnic"/>
    <language>en</language>
    <item>
      <title>What a perfect technical director suggests on career development</title>
      <dc:creator>oleg-melnic</dc:creator>
      <pubDate>Wed, 08 Feb 2023 19:53:06 +0000</pubDate>
      <link>https://dev.to/olegmelnic/what-a-perfect-technical-director-suggests-on-career-development-ld4</link>
      <guid>https://dev.to/olegmelnic/what-a-perfect-technical-director-suggests-on-career-development-ld4</guid>
      <description>&lt;p&gt;Last week, I had a conversation with a technical director. We were discussing the general stuff about software engineering. This guy really knows how all this work because is a very clever director with great leadership skill. So I decided it would be useful for you to learn some insights from him as well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Even senior specialists cannot avoid imposter syndrome
&lt;/h2&gt;

&lt;p&gt;During this conversation, I decided to complain that sometimes I’m not confident about my engineering knowledge and think that everyone around me knows something better than me. He also recollected a situation of failing a coding interview and getting anxious about this. Actually, there’s nothing strange in it because hesitation and anxiety can be quite powerful motivation boosters. Even though I have been working in my company for many years, I still cannot avoid comparing myself with others. He explained that this is normal, even if you have many experiences in the industry. You shouldn’t think that the company that hired you expects you to show the highest-quality performance on the very first day. This is because companies understand that specialists need some time to get used to a new working environment. You shouldn’t be afraid of consulting with people, instead, it’s better to show your complete commitment to learning something new in a new company.&lt;br&gt;
The fact that the senior engineer can digest a piece of code more precisely than the junior, doesn’t mean that this specialist doesn’t use additional tools. When creating a code, seniors also google some basic things, such as the implementation of a hash map in JavaScript. Nevertheless, thanks to the big experience in engineering, a senior can spot the crucial piece regarding the root cause by just taking a look at a block of code. This skill can be gained through experience, so the desire to learn and grow is one of the best methods to deal with imposter syndrome, even if you already have a lot of knowledge to perform stably.&lt;/p&gt;

&lt;h2&gt;
  
  
  Don’t think that soft skills are useless on your way to promotion to senior
&lt;/h2&gt;

&lt;p&gt;One more thing I understood during this conversation is that technical skills aren’t the only features that determine whether you will be promoted to senior. You need to be able to establish efficient cooperation with other team members. This is what differentiates juniors from seniors. Senior specialists have more advanced soft skills that help them to solve different issues more quickly.&lt;br&gt;
Considering this, I realized that engineering managers pay a lot of attention to the personal well-being of specialists. Indeed, he explained to me that if an engineer is in a good mental condition, he can unlock new skills and knowledge faster, which helps to grow professionally and boost performance efficiency. That technical director suggested that engineering managers shouldn’t be too formal when communicating with engineers because casual communication helps to understand whether there are some issues that bother the performance of a specialist. Besides, an engineer will feel a friendly attitude and will understand that he can work without any pressure.&lt;/p&gt;

&lt;h2&gt;
  
  
  To get promoted to a technical director, help specialists under you get promoted
&lt;/h2&gt;

&lt;p&gt;One more interesting insight he shared with me is that a good technical director should care not only about their own personal well-being. It’s necessary to make sure that the things you do can positively impact your team or even the entire company. It’s better to avoid things that are too complicated and have a small impact on the company's performance. This is a basic rule of time management for productive technical directors.&lt;br&gt;
You also need to understand that the more good things your team does for a company, the more chances you have to get promoted. That’s why as a manager, you should pay attention to the professional and personal growth of people under you. If they show great performance and get promoted, you will move a level higher together with them. Actually, this is a way how you can grow to the position of a technical director from a position of a project manager.&lt;/p&gt;

&lt;h2&gt;
  
  
  Focus on learning best practices on code structure, and writing tests
&lt;/h2&gt;

&lt;p&gt;I was also wondering about the most important things at this stage of my career. The technical director suggested that I should sharpen my current skills. This means that I don’t need to spend my time learning new programming languages unless I totally master the skill of code writing and composing its structure. One more thing he shared is that I should always pay attention to unit testing. These are the most important skills to develop at the current stage of my career.&lt;/p&gt;

&lt;h2&gt;
  
  
  Don’t be afraid of working really hard
&lt;/h2&gt;

&lt;p&gt;Some specialists give up the idea of working for a certain company if they think that it cannot provide a “work-life balance”. Frankly speaking, “work-life balance” isn’t the thing you should be looking for in your 20s. You are a healthy young man who can endure such difficulties, especially, if there are great career prospects. Foremost, you should pay attention to the thing that you can gain from this company. Even though you can feel sometimes that you are missing out on your routine life, this is the way to acquire a great reputation in a company and master new technical and soft skills. If it’s too hard, you can always give up, but it would be silly not to try working without considering “work-life balance”.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final thought
&lt;/h2&gt;

&lt;p&gt;To summarize, he suggested that software engineering is the same as vehicle engineering. I took some time to reconsider what he meant and now I can say that I fully agree with it. Similar to a vehicle engineer, you should focus more on a well-defined structure and the process itself rather than different changeable components. Software engineering is all about working on the process and trying new methods. Keep this in mind and you’ll be able to focus on what is really important!&lt;/p&gt;

</description>
      <category>playwright</category>
      <category>mcp</category>
      <category>llm</category>
      <category>testing</category>
    </item>
    <item>
      <title>What is CRUD?</title>
      <dc:creator>oleg-melnic</dc:creator>
      <pubDate>Sun, 04 Apr 2021 16:23:06 +0000</pubDate>
      <link>https://dev.to/olegmelnic/what-is-crud-4id</link>
      <guid>https://dev.to/olegmelnic/what-is-crud-4id</guid>
      <description>&lt;h3&gt;
  
  
  Create, Read, Update, and Delete (CRUD) are the four basic methods for a good functional model.
&lt;/h3&gt;

&lt;h2&gt;
  
  
  Create, Read, Update, Delete
&lt;/h2&gt;

&lt;p&gt;When we create an API, we should provide four basic types of functionality to our model. The model should have the ability to create, read, update and remove resources. Program developers usually refer to these methods as the acronym CRUD. The model must be able to perform a maximum of these four functions in order to be complete. If an action cannot be described in any of these four operations, it should potentially be its own model.&lt;/p&gt;

&lt;p&gt;The CRUD methods are common when building web applications because it provides a memorable basis for reminding developers how to build complete, usable models. For example, let’s imagine a system for tracking library books. In this hypothetical library, a database would be a books resource in which book objects would be stored. Let’s suppose this book object looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;“book”: {
  "id": &amp;lt;Integer&amp;gt;,
  “title”: &amp;lt;String&amp;gt;,
  “author”: &amp;lt;String&amp;gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make this library system usable, we should be sure that there were clear mechanisms for completing the CRUD operations:&lt;br&gt;
Create - is the method we use to add a new library book to the catalogue. The program that invokes the function would give values for &lt;code&gt;title&lt;/code&gt; and &lt;code&gt;author&lt;/code&gt;. When this function is called, a new entry corresponding to this new book should appear in the &lt;code&gt;books&lt;/code&gt; resource. In addition, a new entry is assigned a unique id that can be used to access the resource later. &lt;br&gt;
Read - is the method that we use to view all books in the catalogue. This function call would not change the books in the directory - it would simply get the resource and display the results. We would also have a function to extract a separate book for which we could supply the title, author or ISBN. One more time, this book will not be altered, only found. &lt;br&gt;
Update — is the method we use to change information about a book. The program calling the function would supply the new values for &lt;code&gt;title&lt;/code&gt; and &lt;code&gt;author&lt;/code&gt;. After the function call, the corresponding entry in the books resource would contain the new fields supplied.&lt;br&gt;
Delete — is the method we use to remove a library book from the catalogue. The program calling the function would supply one or more values (&lt;code&gt;title&lt;/code&gt; and/or &lt;code&gt;author&lt;/code&gt;) to identify the book, and then this book would be removed from the books resource. After this function is called, the books resource should contain all of the books it had before, except for the one just deleted.&lt;/p&gt;
&lt;h2&gt;
  
  
  CRUD and REST
&lt;/h2&gt;

&lt;p&gt;In the REST environment, CRUD often corresponds to the HTTP methods POST, GET, PUT and DELETE respectively. These are the four basic elements of a persistent storage system.&lt;br&gt;
In the remainder of the article, we will recommend the response standards and codes that developers usually follow when creating RESTful applications. Conventions may differ, so feel free to experiment with different return values and codes as you become comfortable with the CRUD conception.&lt;br&gt;
Imagine that we’re working with a system that tracks dishes and the relevant prices for the restaurant. Let’s see how we should implement CRUD operations.&lt;/p&gt;
&lt;h2&gt;
  
  
  Create
&lt;/h2&gt;

&lt;p&gt;We commonly use the HTTP POST method to create resources in the REST environment. POST creates a new resource of the specified type.&lt;br&gt;
For example, imagine that we add a new product to the stored list of dishes for this restaurant, and the &lt;code&gt;dish&lt;/code&gt; objects are stored in the &lt;code&gt;dishes&lt;/code&gt; resource. If we wanted to create a new element, we would use the POST request:&lt;br&gt;
Request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;POST http://www.best-restaurant.my/dishes/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Body -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "dish": {
    "name": “Meat Toast”,
    "price": 12
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a new item with a &lt;code&gt;name&lt;/code&gt; value of &lt;code&gt;“Meat Toast”&lt;/code&gt; and a &lt;code&gt;price&lt;/code&gt; value of 12. After successful creation, the server should return a header with a link to the newly-created resource, along with an HTTP response code of 201 (CREATED).&lt;br&gt;
Response:&lt;br&gt;
Status Code - 201 (CREATED)&lt;br&gt;
Body -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "dish": {
    "id": 1463,
    "name": “Meat Toast”,
    "price": 12
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this response, we can see that the &lt;code&gt;dish&lt;/code&gt; with the &lt;code&gt;name&lt;/code&gt; “Meat Toast” and price 8 has been successfully created and added to the &lt;code&gt;dishes&lt;/code&gt; resource.&lt;/p&gt;

&lt;h2&gt;
  
  
  Read
&lt;/h2&gt;

&lt;p&gt;We use the GET method to read resources in the REST environment. Reading a resource should never change any information - it should only retrieve it. If you call GET for the same information 10 times in a row, you must receive the same response to the first call as the last one.&lt;br&gt;
GET can be used to read an entire list of items:&lt;br&gt;
Request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET http://www.best-restaurant.my/dishes/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Response: Status Code - 200 (OK)&lt;br&gt;
Body -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "dishes": [
    {
      "id": 1,
      "name": “Some Rolls”,
      "price": 4
    },
    {
      "id": 2,
      "name": “Mozzarella”,
      "price": 8
    },
    ...
    {
      "id": 1463,
      "name": “Meat Toast”,
      "price": 12
    },
    {
      "id": 1584,
      "name": “Muesli”,
      "price": 3
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;GET requests can also be used to read a specific item when its &lt;code&gt;id&lt;/code&gt; is specified in the request:&lt;br&gt;
Request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET http://www.best-restaurant.my/dishes/1463
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Response: Status Code - 200 (OK) Body -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "id": 1463,
  "name": “Meat Toast”,
  "price": 12
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After this request, no information has been changed in the database. The item with &lt;code&gt;id&lt;/code&gt; 1463 has been retrieved from the &lt;code&gt;dishes&lt;/code&gt; resource, and not modified. When there are no errors, GET will return the HTML or JSON of the desired resource, along with a 200 (OK) response code. If there is an error, it most often will return a 404 (NOT FOUND) response code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Update
&lt;/h2&gt;

&lt;p&gt;PUT is the HTTP method used to update information in the system.&lt;br&gt;
For example, if the price of Avocado Toast has been raised, we should go into the database and update that information. We can do this with a PUT request.&lt;br&gt;
Request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PUT http://www.best-restaurant.my/dishes/1463
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Body -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "dish": {
    "name": “Meat Toast”,
    "price": 10
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This request should change the item with &lt;code&gt;id&lt;/code&gt; 1463 to have the attributes supplied in the request body. This &lt;code&gt;dish&lt;/code&gt; with &lt;code&gt;id&lt;/code&gt; 1463 should now still have the &lt;code&gt;name&lt;/code&gt; &lt;code&gt;“Avocado Toast”&lt;/code&gt;, but the price value should now be 10, as it used to be 12.&lt;br&gt;
Response: Status Code - 200 (OK) Body - not necessary&lt;br&gt;
The response includes a Status Code of 200 (OK) to signify that the operation was successful, but it need not return a response body.&lt;/p&gt;
&lt;h2&gt;
  
  
  Delete
&lt;/h2&gt;

&lt;p&gt;The CRUD operation Delete corresponds to the HTTP method DELETE. It is used to remove a resource from the system.&lt;br&gt;
Let’s say that the world avocado deficit has reached a critical point, and we can no longer afford to serve this modern delicacy at all. We should go into the database and delete the item that corresponds to “Avocado Toast”, which we know has an &lt;code&gt;id&lt;/code&gt; of 1463.&lt;br&gt;
Request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DELETE http://www.best-restaurant.my/dishes/1463
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After the successful operation, we receive a response code of 204 (NO CONTENT) with no response body. The &lt;code&gt;dishes&lt;/code&gt; resource should no longer contain the &lt;code&gt;dish&lt;/code&gt; object with &lt;code&gt;id&lt;/code&gt; 1463.&lt;/p&gt;

&lt;p&gt;Response: Status Code - 204 (NO CONTENT) Body - None&lt;/p&gt;

&lt;p&gt;Calling GET on the &lt;code&gt;dishes&lt;/code&gt; resource after this DELETE call would return the original list of dishes with the &lt;code&gt;{"id": 1463, "name": “Meat Toast”, "price": 10}&lt;/code&gt; entry removed. All other &lt;code&gt;dish&lt;/code&gt; objects in the &lt;code&gt;dishes&lt;/code&gt; resource should remain unchanged. If we tried to call a GET on the item with &lt;code&gt;id&lt;/code&gt; 1463, which we just deleted, we would receive a 404 (NOT FOUND) response code and the state of the system should remain unchanged.&lt;br&gt;
Calling DELETE on a resource that does not exist should not change the state of the system. The call should return a 404 response code (NOT FOUND) and do nothing.&lt;/p&gt;
&lt;h2&gt;
  
  
  CRUD Practice
&lt;/h2&gt;

&lt;p&gt;Create, Read, Update, and Delete methods are fundamental components of a usable storage model. You have already seen above a couple of examples of how the CRUD concept can help us to design systems. Now, try using CRUD to list out routes for a new example model. Imagine that we are creating a system that tracks workout classes, including the name of each class, who teaches it, and the duration of the class. An example &lt;code&gt;class&lt;/code&gt; object would look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "class": {
    "id": 1    
    "name": “Hard Work”,
    “trainer”: “Bob Smeet”,
    "duration": 2.25
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All of the classes are stored in a &lt;code&gt;classes&lt;/code&gt; resource at &lt;code&gt;www.force-academy.com/classes&lt;/code&gt;.&lt;br&gt;
For each CRUD operation, write out answers to the following questions:&lt;br&gt;
    • What routes would you need to implement to provide your workout class model with this CRUD functionality and what are their corresponding HTTP methods?&lt;br&gt;
    • What effect would each route have on the database?&lt;br&gt;
    • What response body would each route return?&lt;br&gt;
    • What response code would each route return?&lt;/p&gt;

&lt;h2&gt;
  
  
  CRUD Practice Answers
&lt;/h2&gt;

&lt;p&gt;1) Create&lt;br&gt;
&lt;strong&gt;Route&lt;/strong&gt;: POST /classes&lt;br&gt;
&lt;strong&gt;Effect on Database&lt;/strong&gt;: Adds the class provided in the request body to the database&lt;br&gt;
&lt;strong&gt;Response Body&lt;/strong&gt;: &lt;code&gt;{ "class": The Newly-Created Class }&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Success Response Code&lt;/strong&gt;: 201&lt;br&gt;
2) Read (All Classes)&lt;br&gt;
&lt;strong&gt;Route&lt;/strong&gt;: GET /classes&lt;br&gt;
&lt;strong&gt;Effect on Database&lt;/strong&gt;: None&lt;br&gt;
&lt;strong&gt;Response Body&lt;/strong&gt;: &lt;code&gt;{ "classes": [ Array of All Saved Classess ] }&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Success Response Code&lt;/strong&gt;: 200&lt;br&gt;
3) Read (One Class)&lt;br&gt;
&lt;strong&gt;Route&lt;/strong&gt;: GET /classes/:id&lt;br&gt;
&lt;strong&gt;Effect on Database&lt;/strong&gt;: None&lt;br&gt;
&lt;strong&gt;Response Body&lt;/strong&gt;: &lt;code&gt;{ "class": The class with the specified ID }&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Success Response Code&lt;/strong&gt;: 200&lt;br&gt;
4) Update&lt;br&gt;
&lt;strong&gt;Route&lt;/strong&gt;: PUT /classes/:id&lt;br&gt;
&lt;strong&gt;Effect on Database&lt;/strong&gt;: Updates the class with the specified ID to have the class information provided in the request body&lt;br&gt;
&lt;strong&gt;Response Body&lt;/strong&gt;: &lt;code&gt;{ "class": The updated class now saved in the database }&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Success Response Code&lt;/strong&gt;: 200&lt;br&gt;
5) Delete&lt;br&gt;
&lt;strong&gt;Route&lt;/strong&gt;: DELETE /classes/:id&lt;br&gt;
&lt;strong&gt;Effect on Database&lt;/strong&gt;: Removes the class with the specified ID from the database&lt;br&gt;
&lt;strong&gt;Response Body&lt;/strong&gt;: None&lt;br&gt;
&lt;strong&gt;Success Response Code&lt;/strong&gt;: 204&lt;br&gt;
As you get more practice with designing storage systems, incorporating CRUD operations into your models will become easier and easier.&lt;/p&gt;

</description>
      <category>crud</category>
      <category>rest</category>
      <category>api</category>
    </item>
    <item>
      <title>What is REST?</title>
      <dc:creator>oleg-melnic</dc:creator>
      <pubDate>Tue, 16 Feb 2021 20:49:43 +0000</pubDate>
      <link>https://dev.to/olegmelnic/what-is-rest-44di</link>
      <guid>https://dev.to/olegmelnic/what-is-rest-44di</guid>
      <description>&lt;h2&gt;
  
  
  REpresentational State Transfer
&lt;/h2&gt;

&lt;p&gt;REST is the acronym for REpresentational State Transfer. It is an architectural style for providing better and easier communication between computer systems on the web. REST-compliant systems, also called RESTful systems, are stateless and act as an intermediary between client and server. We'll take a look at what these terms mean and why they are useful features for online services. &lt;/p&gt;

&lt;h2&gt;
  
  
  Client-Server architecture
&lt;/h2&gt;

&lt;p&gt;In the REST architectural style, the client implementation and the server implementation can be performed independently of each other. This means that the client-side code can be changed at any time without affecting the server's operation, and the server-side code can be changed without affecting the client’s operation.&lt;br&gt;
Messages can be stored modularly and separately, as long as each side knows what message format to send to the other side. By separating user interface tasks from the data storage tasks, we increase the flexibility of the interface between platforms and improve scalability by simplifying server components. Moreover, separation allows each component to evolve independently.&lt;br&gt;
By using the REST interface, different clients end up at the same REST endpoints, perform the same actions, and receive the same responses.&lt;/p&gt;
&lt;h2&gt;
  
  
  Statelessness
&lt;/h2&gt;

&lt;p&gt;Systems that are based on REST architecture are stateless, which means the server doesn't need to know about the client's state and vice versa. Thus, both the server and the client can understand any message received without seeing the previous messages. This statelessness is ensured by using resources rather than commands. Resources are the Web nouns - they describe any objects, documents or things that may be needed to store or send to other services. Because REST systems interact through standard resource operations, they are independent of interface implementation. &lt;br&gt;
These constraints help Restful applications achieve reliability, fast performance, and extensibility as components that can be managed, updated, and reused without affecting the entire system, even while the system is running.&lt;br&gt;
Now, we’ll explore how the communication between the client and server actually happens when we are implementing a RESTful interface.&lt;/p&gt;
&lt;h2&gt;
  
  
  Communication between Client and Server
&lt;/h2&gt;

&lt;p&gt;In REST architecture, clients send requests to find or modify resources, and servers send responses to those requests. Let's take a look at the standard ways of sending requests and responses.&lt;/p&gt;
&lt;h2&gt;
  
  
  Making Requests
&lt;/h2&gt;

&lt;p&gt;REST requires the client to make a request to the server in order to get or change data on the server. The request usually consists of:&lt;br&gt;
    • an HTTP method that determines the type of operation&lt;br&gt;
    • a header, which allows the client to pass along information about the request&lt;br&gt;
    • a path to a resource&lt;br&gt;
    • an optional message body containing data&lt;/p&gt;
&lt;h2&gt;
  
  
  HTTP methods
&lt;/h2&gt;

&lt;p&gt;There are 4 basic HTTP methods we use in requests to interact with resources in a RESTful system:&lt;br&gt;
    • GET — retrieve a specific resource (by id) or a collection of resources&lt;br&gt;
    • POST — create a new resource&lt;br&gt;
    • PUT — update a specific resource (by id)&lt;br&gt;
    • DELETE — remove a specific resource by id&lt;/p&gt;
&lt;h2&gt;
  
  
  Headers and Accept parameters
&lt;/h2&gt;

&lt;p&gt;In the header of the request, the client sends the type of content that it is able to receive from the server. This field is called Accept, and it ensures that the server does not send data that cannot be understood or processed by the client. Content-type parameters are MIME types (or Multipurpose Internet Mail Extensions, which you can read more about in the MDN Web Docs).&lt;br&gt;
MIME Types, used to specify the content types in the &lt;code&gt;Accept&lt;/code&gt; field, consist of a &lt;code&gt;type&lt;/code&gt; and a &lt;code&gt;subtype&lt;/code&gt;. They are separated by a slash (/).&lt;br&gt;
For example, a text file containing HTML would be specified with the type &lt;code&gt;text/html&lt;/code&gt;. If this text file contained CSS instead, it would be specified as &lt;code&gt;text/css&lt;/code&gt;. The general text file will be referred to as &lt;code&gt;text/plain&lt;/code&gt;. However, this default value, &lt;code&gt;text/plain&lt;/code&gt;, is not universal. If a client is expecting &lt;code&gt;text/css&lt;/code&gt; and receives &lt;code&gt;text/plain&lt;/code&gt;, it will not be able to recognize the content.&lt;br&gt;
Other types and commonly used subtypes:&lt;br&gt;
    • &lt;code&gt;image&lt;/code&gt; — &lt;code&gt;image/png&lt;/code&gt;, &lt;code&gt;image/jpeg&lt;/code&gt;, &lt;code&gt;image/gif&lt;/code&gt;&lt;br&gt;
    • &lt;code&gt;audio&lt;/code&gt; — &lt;code&gt;audio/wav&lt;/code&gt;, &lt;code&gt;audio/mpeg&lt;/code&gt;&lt;br&gt;
    • &lt;code&gt;video&lt;/code&gt; — &lt;code&gt;video/mp4&lt;/code&gt;, &lt;code&gt;video/ogg&lt;/code&gt;&lt;br&gt;
    • &lt;code&gt;application&lt;/code&gt; — &lt;code&gt;application/json&lt;/code&gt;, &lt;code&gt;application/pdf&lt;/code&gt;, &lt;code&gt;application/xml&lt;/code&gt;, &lt;code&gt;application/octet-stream&lt;/code&gt;&lt;br&gt;
For example, a client accessing a resource with &lt;code&gt;id&lt;/code&gt; 23 in an &lt;code&gt;articles&lt;/code&gt; resource on a server might send a GET request like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /articles/23
Accept: text/html, application/xhtml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;Accept&lt;/code&gt; header field, in this case, is saying that the client will accept the content in &lt;code&gt;text/html&lt;/code&gt; or &lt;code&gt;application/xhtml&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Paths
&lt;/h2&gt;

&lt;p&gt;Requests must contain a path to a resource that the operation should be performed on. In RESTful APIs, paths should be designed to help the client know what is going on.&lt;br&gt;
Usually, the first part of the path should be the plural form of the resource. This allows easy reading and understanding of nested paths.&lt;br&gt;
A path like &lt;code&gt;blabla.ccc/customers/223/orders/12&lt;/code&gt; is clear in what it points to, even if you’ve never seen this specific path before because it is hierarchical and descriptive. We can see that we are accessing the order with &lt;code&gt;id&lt;/code&gt; 12 for the customer with &lt;code&gt;id&lt;/code&gt; 223.&lt;br&gt;
Paths should contain the information necessary to locate a resource with the degree of specificity needed. When referring to a list or collection of resources, it is not always necessary to add an id. For example, a POST request to the &lt;code&gt;blabla.ccc/customers&lt;/code&gt; path would not need an extra identifier, as the server will generate an id for the new object.&lt;br&gt;
If we are trying to access a single resource, we would need to add an &lt;code&gt;id&lt;/code&gt; to the path. For example: GET &lt;code&gt;blabla.ccc/customers/:id&lt;/code&gt; — retrieves the item in the customers resource with the id specified. DELETE &lt;code&gt;blabla.ccc/customers/:id&lt;/code&gt; — deletes the item in the customers resource with the id specified.&lt;/p&gt;
&lt;h2&gt;
  
  
  Sending Responses
&lt;/h2&gt;
&lt;h2&gt;
  
  
  Content Types
&lt;/h2&gt;

&lt;p&gt;In cases where the server is sending a data payload to the client, the server must include a &lt;code&gt;content-type&lt;/code&gt; in the header of the response. This &lt;code&gt;content-type&lt;/code&gt; header field alerts the client to the type of data it is sending in the response body. These content types are MIME Types, just as they are in the &lt;code&gt;accept&lt;/code&gt; field of the request header. The &lt;code&gt;content-type&lt;/code&gt; that the server sends back in the response should be one of the options that the client specified in the &lt;code&gt;accept&lt;/code&gt; field of the request.&lt;br&gt;
For example, when a client is accessing a resource with &lt;code&gt;id&lt;/code&gt; 23 in an &lt;code&gt;articles&lt;/code&gt; resource with this GET Request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /articles/23 HTTP/1.1
Accept: text/html, application/xhtml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The server might send back the content with the response header:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP/1.1 200 (OK)
Content-Type: text/html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would signify that the content requested is being returned in the response body with a &lt;code&gt;content-type&lt;/code&gt; of &lt;code&gt;text/html&lt;/code&gt;, which the client said it would be able to accept.&lt;/p&gt;

&lt;h2&gt;
  
  
  Response Codes
&lt;/h2&gt;

&lt;p&gt;Responses from the server contain status codes to alert the client to information about the success of the operation. As a developer, you do not need to know every status code (there are many of them), but you should know the most common ones and how they are used:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Status code&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;200 (OK)&lt;/td&gt;
&lt;td&gt;This is the standard response for successful HTTP requests.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;201 (CREATED)&lt;/td&gt;
&lt;td&gt;This is the standard response for an HTTP request that resulted in an item being successfully created.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;204 (NO CONTENT)&lt;/td&gt;
&lt;td&gt;This is the standard response for successful HTTP requests, where nothing is being returned in the response body.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;400 (BAD REQUEST)&lt;/td&gt;
&lt;td&gt;The request cannot be processed because of bad request syntax, excessive size, or another client error.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;403 (FORBIDDEN)&lt;/td&gt;
&lt;td&gt;The client does not have permission to access this resource.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;404 (NOT FOUND)&lt;/td&gt;
&lt;td&gt;The resource could not be found at this time. It is possible it was deleted, or does not exist yet.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;500 (INTERNAL SERVER ERROR)&lt;/td&gt;
&lt;td&gt;The generic answer for an unexpected failure if there is no more specific information available.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For each HTTP verb, there are expected status codes a server should return upon success:&lt;br&gt;
    • GET — return 200 (OK)&lt;br&gt;
    • POST — return 201 (CREATED)&lt;br&gt;
    • PUT — return 200 (OK)&lt;br&gt;
    • DELETE — return 204 (NO CONTENT) If the operation fails, return the most specific status code possible corresponding to the problem that was encountered.&lt;/p&gt;
&lt;h2&gt;
  
  
  Examples of Requests and Responses
&lt;/h2&gt;

&lt;p&gt;Let’s suppose we have an application that allows you to view, create, edit, and delete customers and orders for a small clothing store hosted at blabla.ccc. We could create an HTTP API that allows a client to perform the following functions:&lt;br&gt;
If we wanted to view all customers, the request would look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET http://fashionboutique.com/customers
Accept: application/json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A possible response header would look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Status Code: 200 (OK)
Content-type: application/json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;followed by the &lt;code&gt;customers&lt;/code&gt; data requested in &lt;code&gt;application/json&lt;/code&gt; format.&lt;br&gt;
Create a new customer by posting the data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;POST http://blabla.ccc/customers
Body:
{
  “customer”: {
    “name” = “Vasea Pupkin”,
    “email” = “vasea.pepkin@exemple.ccc”
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The server then generates an &lt;code&gt;id&lt;/code&gt; for that object and returns it back to the client, with a header like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;201 (CREATED)
Content-type: application/json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To view a single customer we GET it by specifying that customer’s id:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET http://fashionboutique.com/customers/123
Accept: application/json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A possible response header would look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Status Code: 200 (OK)
Content-type: application/json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;followed by the data for the customer resource with id 23 in application/json format.&lt;br&gt;
We can update that customer by PUT ting the new data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PUT http://blabla.ccc/customers/123
Body:
{
  “customer”: {
    “name” = “Vasea Pupkin”,
    “email” = “vaseapupkin1@exemple.ccc”
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A possible response header would have &lt;code&gt;Status Code: 200 (OK)&lt;/code&gt;, to notify the client that the item with &lt;code&gt;id&lt;/code&gt; 123 has been modified.&lt;br&gt;
We can also DELETE that customer by specifying its &lt;code&gt;id&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DELETE http://blabla.ccc/customers/123
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The response would have a header containing &lt;code&gt;Status Code: 204 (NO CONTENT)&lt;/code&gt;, notifying the client that the item with &lt;code&gt;id&lt;/code&gt; 123 has been deleted, and nothing in the body.&lt;/p&gt;

&lt;h2&gt;
  
  
  Practice with REST
&lt;/h2&gt;

&lt;p&gt;Let’s imagine we are building a photo-collection site. We want to make an API to keep track of users, venues, and photos of those venues. This site has an &lt;code&gt;index.html&lt;/code&gt; and a &lt;code&gt;style.css&lt;/code&gt;. Each user has a username and a password. Each photo has a venue and an owner (i.e. the user who took the picture). Each venue has a name and street address. Can you design a REST system that would accommodate:&lt;br&gt;
    • storing users, photos, and venues&lt;br&gt;
    • accessing venues and accessing certain photos of a certain venue&lt;br&gt;
Start by writing out:&lt;br&gt;
    • what kinds of requests we would want to make&lt;br&gt;
    • what responses the server should return&lt;br&gt;
    • what the &lt;code&gt;content-type&lt;/code&gt; of each response should be&lt;/p&gt;

&lt;h2&gt;
  
  
  Possible Solution - Models
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  “user”: {
    "id": &amp;lt;Integer&amp;gt;,
    “username”: &amp;lt;String&amp;gt;,
    “password”:  &amp;lt;String&amp;gt;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  “photo”: {
    "id": &amp;lt;Integer&amp;gt;,
    “venue_id”: &amp;lt;Integer&amp;gt;,
    “author_id”: &amp;lt;Integer&amp;gt;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  “venue”: {
    "id": &amp;lt;Integer&amp;gt;,
    “name”: &amp;lt;String&amp;gt;,
    “address”: &amp;lt;String&amp;gt;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Possible Solution - Requests/Responses
&lt;/h2&gt;

&lt;h2&gt;
  
  
  GET Requests
&lt;/h2&gt;

&lt;p&gt;Request- &lt;code&gt;GET /index.html&lt;/code&gt; Accept: &lt;code&gt;text/html&lt;/code&gt; Response- 200 (OK) Content-type: &lt;code&gt;text/html&lt;/code&gt;&lt;br&gt;
Request- &lt;code&gt;GET /style.css&lt;/code&gt; Accept: &lt;code&gt;text/css&lt;/code&gt; Response- 200 (OK) Content-type: &lt;code&gt;text/css&lt;/code&gt;&lt;br&gt;
Request- &lt;code&gt;GET /venues&lt;/code&gt; Accept:&lt;code&gt;application/json&lt;/code&gt; Response- 200 (OK) Content-type: &lt;code&gt;application/json&lt;/code&gt;&lt;br&gt;
Request- &lt;code&gt;GET /venues/:id&lt;/code&gt; Accept: &lt;code&gt;application/json&lt;/code&gt; Response- 200 (OK) Content-type: &lt;code&gt;application/json&lt;/code&gt;&lt;br&gt;
Request- &lt;code&gt;GET /venues/:id/photos/:id&lt;/code&gt; Accept: &lt;code&gt;application/json&lt;/code&gt; Response- 200 (OK) Content-type: &lt;code&gt;image/png&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  POST Requests
&lt;/h2&gt;

&lt;p&gt;Request- &lt;code&gt;POST /users&lt;/code&gt; Response- 201 (CREATED) Content-type: application/json&lt;br&gt;
Request- POST /venues Response- 201 (CREATED) Content-type: application/json&lt;br&gt;
Request- POST /venues/:id/photos Response- 201 (CREATED) Content-type: &lt;code&gt;application/json&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  PUT Requests
&lt;/h2&gt;

&lt;p&gt;Request- &lt;code&gt;PUT /users/:id&lt;/code&gt; Response- 200 (OK)&lt;br&gt;
Request- &lt;code&gt;PUT /venues/:id&lt;/code&gt; Response- 200 (OK)&lt;br&gt;
Request- &lt;code&gt;PUT /venues/:id/photos/:id&lt;/code&gt; Response- 200 (OK)&lt;/p&gt;

&lt;h2&gt;
  
  
  DELETE Requests
&lt;/h2&gt;

&lt;p&gt;Request- &lt;code&gt;DELETE /venues/:id&lt;/code&gt; Response- 204 (NO CONTENT)&lt;br&gt;
Request- &lt;code&gt;DELETE /venues/:id/photos/:id&lt;/code&gt; Response- 204 (NO CONTENT)&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Strategy Pattern</title>
      <dc:creator>oleg-melnic</dc:creator>
      <pubDate>Mon, 28 Dec 2020 14:22:57 +0000</pubDate>
      <link>https://dev.to/olegmelnic/strategy-pattern-41ff</link>
      <guid>https://dev.to/olegmelnic/strategy-pattern-41ff</guid>
      <description>&lt;p&gt;The first step in learning this pattern is defining a problem and solving it by using a strategy pattern. Imagine that we are developing a game “Street Fighter”. For convenience, let’s suppose that a character has four different moves. They are - kick, punch, roll and jump.  For each character kick and punch moves are compulsory, but roll and jump are additional. How should your classes be modeled? Considering that you use inheritance and abstract out the common features in a Fighter class and let other characters subclass Fighter class.&lt;/p&gt;

&lt;p&gt;Fighter class will have default implementation of regular actions. Any character with a specific move can override that action in its subclass. You can see this on Class diagram below:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2t0wla2ff7hm37h23foe.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2t0wla2ff7hm37h23foe.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Which problems does the above design have?&lt;/p&gt;

&lt;p&gt;For example, character doesn’t perform jump move.  It still inherits the jump behavior from the main class. In that event you can simply override jump, but you may have to do such operations for all existing classes and furthermore, keep in your mind that future classes should be worried about that too. So inheritance is not the appropriate principle here.&lt;/p&gt;

&lt;p&gt;What about an Interface?&lt;/p&gt;

&lt;p&gt;Look at the design below:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fldesswskgqoj6s1mzglc.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fldesswskgqoj6s1mzglc.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It’s pretty well-ordered. Actions, which some characters might not perform, were removed out of Fighterclass and interfaces were created for them instead. It means that only characters that are supposed to jump will implement the JumpBehavior.&lt;/p&gt;

&lt;p&gt;Which problems does the above design have?&lt;br&gt;
Code reuse is the main problem with this kind of design. We may duplicate code, because there is no default implementation of jump and roll behavior.  In that way we may need to rewrite the same jump behavior again and again in many subclasses.&lt;br&gt;
 How to avoid this?&lt;br&gt;
 At first sight, the most efficient way is to use multiple inheritance and create JumpBehavior and RollBehavior classes instead of interface. But due to the fact, that multiple inheritance is not supported in many languages and has too many problems with it, we cannot use it.&lt;br&gt;
 Here strategy pattern comes to help us. We need to learn what the strategy pattern is and then apply it to solve our problem.&lt;/p&gt;

&lt;p&gt;Definition:&lt;/p&gt;

&lt;p&gt;Wikipedia defines strategy pattern as:&lt;/p&gt;

&lt;p&gt;“In computer programming, the strategy pattern (also known as the policy pattern) is a software design pattern that enables an algorithm’s behavior to be selected at runtime. The strategy pattern:&lt;/p&gt;

&lt;p&gt;·         defines a family of algorithms,&lt;br&gt;
·         encapsulates each algorithm,&lt;br&gt;
·         makes the algorithms interchangeable within that family.”&lt;/p&gt;

&lt;p&gt;Class scheme:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Folnc0xortf0817l99tef.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Folnc0xortf0817l99tef.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Instead of inheritance for reuse we focus on composition here. Context is made up of a Strategy. The Context delegates a behavior to Strategy instead of implementing it. The context class will require the behavior change, which   can be dynamic. So we can change behavior without affecting our context, because Strategy is implemented as an interface.&lt;br&gt;
To have a deeper understanding of strategy pattern we should use it in practice to solve our problem.&lt;/p&gt;

&lt;p&gt;Advantages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;    We can define a family of algorithms as a class hierarchy, which is interchangeable to alter application behavior and can use it without modifying its architecture.&lt;/li&gt;
&lt;li&gt;     We can easily introduce new algorithms complying with the same interface by encapsulating the algorithm individually.&lt;/li&gt;
&lt;li&gt;    Strategies can be switched at run-time.&lt;/li&gt;
&lt;li&gt;    We have an opportunity to choose the required algorithm, without using a “switch” statement or a series of “if-else” statements.&lt;/li&gt;
&lt;li&gt;    We can change the implementation of an algorithm without affecting the Context class because Data structures used for implementing the algorithm are completely encapsulated in Strategy classes.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Disadvantages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;    The right strategy for the right situation could be selected only if the application includes all the strategies.&lt;/li&gt;
&lt;li&gt;    Normally, communication between Context and the Strategy classes is carried out through the interface established by the abstract Strategy base class. Some concrete Strategy classes might not implement all the required behaviors, although Strategy base class must provide interface for them.&lt;/li&gt;
&lt;li&gt;    The Context can be configured with the required Strategy object in most cases. Therefore, two objects instead of one need to be built and supported.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Then we will apply the strategy pattern to the problems with fighter and talk about the implementation.&lt;/p&gt;

&lt;p&gt;The main thing is the identification of behaviors that may differ from class to class after time and then their separation from the others. For example, let that behaviors be kicks and jumps. For their separation, we will extract both methods from the Fighter class and design a new set of classes to show each behavior.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fab2fvtcrwtm1prt1fxla.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fab2fvtcrwtm1prt1fxla.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, kick and jump behavior will be delegated to the Fighter class, instead of using the kick and jump methods defined in the Fighter class or its subclass.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fogx16sbijeo5js7pu0ez.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fogx16sbijeo5js7pu0ez.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After this modification, the final class diagram will look like (Click the image for a better view):&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ftwh7yxusbqjm6l7dlbvb.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ftwh7yxusbqjm6l7dlbvb.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In comparison with the definition of a strategy pattern and our design, encapsulated kick and jump behaviors are two families of algorithms. And these algorithms can be replaced with each other, as can be seen from the implementation.&lt;/p&gt;

</description>
      <category>patterns</category>
      <category>architecture</category>
      <category>strategy</category>
      <category>development</category>
    </item>
  </channel>
</rss>
