<?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: ROHIT SINGH</title>
    <description>The latest articles on DEV Community by ROHIT SINGH (@rohitsingh09).</description>
    <link>https://dev.to/rohitsingh09</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%2F771619%2F140d4e83-9b3e-4b88-885b-63bb9864f2b2.png</url>
      <title>DEV Community: ROHIT SINGH</title>
      <link>https://dev.to/rohitsingh09</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rohitsingh09"/>
    <language>en</language>
    <item>
      <title>How to detect SOLID principle violations?</title>
      <dc:creator>ROHIT SINGH</dc:creator>
      <pubDate>Sat, 28 Sep 2024 05:45:10 +0000</pubDate>
      <link>https://dev.to/rohitsingh09/how-to-detect-solid-principle-violations-18c0</link>
      <guid>https://dev.to/rohitsingh09/how-to-detect-solid-principle-violations-18c0</guid>
      <description>&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Single Responsibility (SRP):&lt;/strong&gt;&lt;br&gt;
&lt;u&gt;Symptom&lt;/u&gt;: Large classes handling multiple tasks.&lt;br&gt;
&lt;u&gt;Detection&lt;/u&gt;: Check for classes with too many responsibilities or methods. Use tools like SonarQube for complexity warnings.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Open/Closed (OCP):&lt;/strong&gt;&lt;br&gt;
&lt;u&gt;Symptom&lt;/u&gt;: Modifying existing classes for new features.&lt;br&gt;
&lt;u&gt;Detection&lt;/u&gt;: Review change logs and check for frequent edits to core classes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Liskov Substitution (LSP):&lt;/strong&gt;&lt;br&gt;
&lt;u&gt;Symptom&lt;/u&gt;: Subclasses that break functionality when used in place of base classes.&lt;br&gt;
&lt;u&gt;Detection&lt;/u&gt;: Write unit tests that fail when incorrect subclass behavior is introduced.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Interface Segregation (ISP):&lt;/strong&gt;&lt;br&gt;
&lt;u&gt;Symptom&lt;/u&gt;: Classes implementing methods they don't use.&lt;br&gt;
&lt;u&gt;Detection&lt;/u&gt;: Look for bloated interfaces. Check if classes use all implemented methods.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dependency Inversion (DIP):&lt;/strong&gt;&lt;br&gt;
&lt;u&gt;Symptom&lt;/u&gt;: High coupling between classes.&lt;br&gt;
&lt;u&gt;Detection&lt;/u&gt;: Identify direct dependencies on concrete classes. Use tools like NDepend to detect tight coupling.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;💡General Tips: Use code reviews, static analysis tools (SonarQube, NDepend), and automated tests to catch violations.&lt;/p&gt;

</description>
      <category>solidprinciples</category>
      <category>cleancode</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>Angular: Lifecycle hooks and their practical usage</title>
      <dc:creator>ROHIT SINGH</dc:creator>
      <pubDate>Fri, 03 Jun 2022 16:04:06 +0000</pubDate>
      <link>https://dev.to/rohitsingh09/angular-lifecycle-hooks-and-their-practical-usage-7k4</link>
      <guid>https://dev.to/rohitsingh09/angular-lifecycle-hooks-and-their-practical-usage-7k4</guid>
      <description>&lt;p&gt;Any Angular project is just a bunch of components that serves the specific feature of application and each and every component follows a lifecycle that starts when Angular instantiates the component class and renders the view along with its child view. &lt;/p&gt;

&lt;p&gt;In this post we will try to understand how can we as a developer implement the life cycle hooks in our application.&lt;/p&gt;

&lt;p&gt;After the application instantiate a component by calling the constructor, Angular starts calling the lifecycle hooks which is implemented by you in the lifecycle of that component instance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxwlabfng6eg4mm6kzufp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxwlabfng6eg4mm6kzufp.png" alt="Angular Lifecycle hooks" width="258" height="358"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note: constructor is the feature of TypeScript, so Angular does not treat this as a part of lifecycle hooks.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Angular executes hooks methods in the following sequence:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- ngOnChanges()
- ngOnInit()
- ngDoCheck()
- ngAfterContentInit()
- ngAfterContentChecked()
- ngAfterViewInit()
- ngAfterViewChecked()
- ngOnDestroy()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;&lt;strong&gt;ngOnChanges()&lt;/strong&gt;&lt;/u&gt;: A lifecycle hook that is called whenever any data bound property gets change. This is the first lifecycle hook that gets executed whenever a component gets instantiated. This method also receives a &lt;strong&gt;SimpleChanges&lt;/strong&gt; object of current and previous property values. ngOnChanges() method called on every update of &lt;strong&gt;@input()&lt;/strong&gt; properties. The biggest advantages of using ngOnChanges() is that you will get all changes at once if your component has more that one &lt;strong&gt;@input()&lt;/strong&gt; properties. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Note: If your component doesn't have any @input() property then angular will never call ngOnChanges() even though you're using it.&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;ngOnChanges&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;changes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;SimpleChange&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;currentChange&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;changes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentValue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;previousChange&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;changes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;previousValue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;isFirstChange&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;changes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstChange&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;u&gt;ngOnInit():&lt;/u&gt;&lt;/strong&gt; This lifecycle hook called by Angular to indicate that Angular is done creating the component. We use this hook for all the initialization/declaration and avoid stuff to work in the constructor.&lt;br&gt;
&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="nf"&gt;ngOnInit&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//this is the right place for all the initializations.&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;u&gt;ngDoCheck():&lt;/u&gt;&lt;/strong&gt; This hook will detect or act upon those changes that Angular can't or won't detect on its own. The ngDoCheck() detects deep changes like a property change in object or item is pushed into array even without reference change. In more simpler terms.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;It's generally a component check on following occasions.
  - Update child component input binding
  - Update DOM interpolation.
  - Update query list.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="nf"&gt;ngDoCheck&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//this is the where we write our logic whenever an application has to respond upon certain changes.&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;u&gt;ngAfterContentInit():&lt;/u&gt;&lt;/strong&gt; This hook responds after Angular completes initialization of directive's content and after every default change detection. We can also define an ngAfterContentInit() method in our component to handle any additional initialization tasks. This hook gets called after components external content (content passed by ng-content directive) has been initialized.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="nf"&gt;ngAfterContentInit&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;u&gt;ngAfterContentChecked():&lt;/u&gt;&lt;/strong&gt; It responds after Angular checks the content projected into the directive or component. This hook gets called after ngAfterContentInit() and every subsequent ngDoCheck(). It can be useful if you want to implement additional initialization tasks after Angular has fully initialized the component/directive's content.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="nf"&gt;ngAfterContentChecked&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;//all extra initialization tasks can get implemented here.. &lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;u&gt;ngAfterViewInit():&lt;/u&gt;&lt;/strong&gt; This hooks respond after Angular initializes the component's views and child views, or the view that contains the directive. It is invoked only once when the view is instantiated. This is the best place where we can access our DOM nodes and perform any manipulation on them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="nf"&gt;ngAfterViewInit&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;u&gt;ngAfterViewChecked():&lt;/u&gt;&lt;/strong&gt; It respond after Angular checks the component's views and child views, or the view that contains the directive and get called after the ngAfterViewInit() and every subsequent ngAfterContentChecked().The ngAfterViewChecked() would be invoked once the DOM tree get any change. So if the DOM tree got change for many times, the ngAfterViewChecked() method would be invoked many times.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="nf"&gt;ngAfterViewChecked&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;u&gt;ngOnDestroy():&lt;/u&gt;&lt;/strong&gt; This hook gets called immediately before Angular destroys the directive or component. So, all the cleanup functions like unsubscribing the observables and detach event handlers to avoid memory leaks can get implemented here. This hooks gets called only once per lifetime cycle.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="nf"&gt;ngOnDestroy&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//write all your cleanup logic here..&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔥 Hopefully, this article has illustrated all the insight from Angular Lifecycle Hooks and if you find this article helpful then give it a love.❤&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>angular</category>
      <category>typescript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
