<?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: Amohammadi2</title>
    <description>The latest articles on DEV Community by Amohammadi2 (@ashkanmohammadi).</description>
    <link>https://dev.to/ashkanmohammadi</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%2F640012%2F8c9d76dc-eec3-48db-a0de-9e3b6cd97c4f.jpg</url>
      <title>DEV Community: Amohammadi2</title>
      <link>https://dev.to/ashkanmohammadi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ashkanmohammadi"/>
    <language>en</language>
    <item>
      <title>Eliminate Circular Dependencies With Layered Modular Architecture</title>
      <dc:creator>Amohammadi2</dc:creator>
      <pubDate>Mon, 15 Aug 2022 06:09:51 +0000</pubDate>
      <link>https://dev.to/ashkanmohammadi/eliminate-circular-dependencies-with-layered-modular-architecture-32gn</link>
      <guid>https://dev.to/ashkanmohammadi/eliminate-circular-dependencies-with-layered-modular-architecture-32gn</guid>
      <description>&lt;p&gt;Modular Design is very important in any large scale application. It helps with decoupling application domains, enables developers to focus only on their specific domains and makes the on-boarding process a lot easier. Also, if you decide to split your monolith into microservices, it will be less painful.&lt;/p&gt;

&lt;p&gt;The basic idea behind modular design is to organize your project files based on their purpose instead of their type. &lt;/p&gt;

&lt;p&gt;One of the most common problems you'll encounter during the process of modularizing your app, is the trap of circular-dependency between your modules. Circular dependencies are often an indicator of the need to extract a third module or merge the two.&lt;/p&gt;

&lt;p&gt;But how to organize them?&lt;/p&gt;

&lt;h2&gt;
  
  
  Layered Modules
&lt;/h2&gt;

&lt;p&gt;I've personally encountered the problem of circular dependencies in &lt;strong&gt;EVERY&lt;/strong&gt; project that I have worked on.&lt;/p&gt;

&lt;p&gt;One time, as I was diagnosing the structure of one of my apps to find the origin of circular dependencies between its modules, I realized that the modules can function independently only up to a certain layer.&lt;/p&gt;

&lt;p&gt;In this concrete example, the problem was the API layer (the app was a back-end service). I needed to aggregate information from multiple modules to finally accomplish the task and output the results to the front-end developers.&lt;/p&gt;

&lt;p&gt;So I decided to change the project structure from this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4Q8z7TbZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/td092pfikkb8khd57ivi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4Q8z7TbZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/td092pfikkb8khd57ivi.png" alt="previous structure" width="880" height="428"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y-1UxoEq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/da72fl2digzkye975muc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y-1UxoEq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/da72fl2digzkye975muc.png" alt="current structure" width="880" height="428"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And after the refactoring process was done, there was no circular dependencies between my modules anymore. Also, the module hierarchy was much more easier to understand.&lt;/p&gt;

&lt;p&gt;As you can see, This structure is a combination of layered architecture and modular design. You can personalize this to fit your own needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  How do I organize my modules now?
&lt;/h2&gt;

&lt;p&gt;Currently, I categorize my modules into 3 main categories:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/src
  /db-modules
  /feature-modules
  /api-modules
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_R-CQsw1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2x926cr70wrgb0aryski.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_R-CQsw1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2x926cr70wrgb0aryski.png" alt="Module Layer Hierarchy" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  DB Modules
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;They can manage and validate the database models related to their domains independently&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  feature Modules
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;They can manage and validate the database models related to their domains independently&lt;/li&gt;
&lt;li&gt;They implement logic and perform business tasks independently&lt;/li&gt;
&lt;li&gt;They can import from DB Modules&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  API Modules
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;They can manage and validate the database models related to their domains independently&lt;/li&gt;
&lt;li&gt;They implement logic and perform business tasks independently&lt;/li&gt;
&lt;li&gt;They implement the API interface and handle API requests independently (without relying on other API modules)&lt;/li&gt;
&lt;li&gt;They can import from DB Modules&lt;/li&gt;
&lt;li&gt;They can import from Feature Modules&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Basically, the extent to which a module can handle its own concerns, determines the type of the module. Also you can introduce more groups as the complexity grows (e.g: you can add an aggregator module group to integrate multiple API modules which is useful for dealing with microservices and external APIs).&lt;/p&gt;

&lt;p&gt;What do you think about this architecture? leave a comment down below&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>architecture</category>
      <category>productivity</category>
      <category>programming</category>
    </item>
    <item>
      <title>Casino_plus, an easy way to create uniform and non-uniform random distributions</title>
      <dc:creator>Amohammadi2</dc:creator>
      <pubDate>Thu, 03 Jun 2021 19:19:26 +0000</pubDate>
      <link>https://dev.to/ashkanmohammadi/casinoplus-an-easy-way-to-create-uniform-and-non-uniform-random-distributions-2g28</link>
      <guid>https://dev.to/ashkanmohammadi/casinoplus-an-easy-way-to-create-uniform-and-non-uniform-random-distributions-2g28</guid>
      <description>&lt;p&gt;Casino_plus is a &lt;strong&gt;C++ library&lt;/strong&gt; for creating both uniform and non-uniform random distributions. The good thing about this library is, it has &lt;strong&gt;python language bindings&lt;/strong&gt; as well, so you can use it in your python projects as well.&lt;/p&gt;

&lt;p&gt;This library has a very easy to use interface for python programmers, also it is really fast.&lt;/p&gt;

&lt;p&gt;In this article, I want to show you how to use python bindings of this library. So let's begin&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;the installation process is fairly simple. here is the requirements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Visual C++ build tools 2017 or higher&lt;/li&gt;
&lt;li&gt;CMake version 3.8 or higher&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;here is the github repo:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/Amohammadi2" rel="noopener noreferrer"&gt;
        Amohammadi2
      &lt;/a&gt; / &lt;a href="https://github.com/Amohammadi2/Casino_plus" rel="noopener noreferrer"&gt;
        Casino_plus
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      create uniform and non-uniform distribution
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;first go ahead and clone the repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git clone https://github.com/Amohammadi2/Casino_plus.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, &lt;code&gt;cd&lt;/code&gt; into the project root directory, there you can find a setup.py file. (installation verified on python version 3.8)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ python setup.py install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you have the required tools installed, the installation will finish successfully.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use it
&lt;/h2&gt;

&lt;p&gt;you have to import the module before you can use it, write the following code in a python file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import CasinoPlus
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the module contains a class called &lt;code&gt;CasinoRandomGenerator&lt;/code&gt; but due to constraints of C++ type system, there are some prefixes that you should use based on the data type you want to pass to the generator.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;s_ : for generators containing strings&lt;/li&gt;
&lt;li&gt;cs_ : for generators containing chars&lt;/li&gt;
&lt;li&gt;i_ : for generators containing ints&lt;/li&gt;
&lt;li&gt;f_ : for generators containing floats&lt;/li&gt;
&lt;li&gt;d_ : for generators containing doubles&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;for example you could use: &lt;code&gt;s_CasinoRandomGenerator&lt;/code&gt; to create a generator that accepts string items&lt;/p&gt;

&lt;p&gt;at the time being, only the types mentioned above are supported. We'll try to improve it and make it more general.&lt;/p&gt;

&lt;h3&gt;
  
  
  adding items to the generator
&lt;/h3&gt;

&lt;p&gt;to add items to the generator, you should use one of the methods &lt;code&gt;add_item&lt;/code&gt; or &lt;code&gt;add_sequence&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;add_item(item: Item_Type, probability: int) -&amp;gt; None&lt;/code&gt; : adds one item to generator with specified probability. for uniform distributions &lt;code&gt;probability&lt;/code&gt; could be set to 1 for all the items but if you want to create non-uniform random distributions, you can change this value. For example if you want the item to appear more frequently, you can increase the probability. &lt;strong&gt;probability cannot be a negative value&lt;/strong&gt;. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;add_sequence(items: List[Tuple[Item_Type, int]]) -&amp;gt; None&lt;/code&gt; : can add multiple items at once. it is more optimal to use this function when you want to add multiple items to the generator.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;notice that &lt;code&gt;Item_Type&lt;/code&gt; is actually the data type that the generator is using for example if you're using &lt;code&gt;s_CasinoRandomGenerator&lt;/code&gt; then Item_Type would be &lt;code&gt;str&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  getting a random item out of generator
&lt;/h3&gt;

&lt;p&gt;in order to get a random item, you should use &lt;code&gt;get_random_item&lt;/code&gt; method. It has the following signature:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;get_random_item() -&amp;gt; Item_Type
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  example
&lt;/h2&gt;

&lt;p&gt;here is a example program that uses all the functionalities of  CasinoPlus.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; from CasinoPlus import s_CasinoRandomGenerator as strgen
&amp;gt;&amp;gt;&amp;gt;
&amp;gt;&amp;gt;&amp;gt; rand = strgen()
&amp;gt;&amp;gt;&amp;gt; rand.add_item("Ashkan Mohammadi", 1)
&amp;gt;&amp;gt;&amp;gt; my_brothers = [["Arshia Mohammadi", 1], ["Ilia Mohammadi", 1]]
&amp;gt;&amp;gt;&amp;gt;
&amp;gt;&amp;gt;&amp;gt; rand.add_sequence(my_brothers)
&amp;gt;&amp;gt;&amp;gt; rand.get_random_item()
'Ilia Mohammadi'
&amp;gt;&amp;gt;&amp;gt; rand.get_random_item()
'Ashkan Mohammadi'
&amp;gt;&amp;gt;&amp;gt; rand.get_random_item()
'Arshia Mohammadi'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>cpp</category>
      <category>python</category>
      <category>randomdistributions</category>
    </item>
  </channel>
</rss>
