Solid Principle examples

0 votes
Even if we aren't aware of it, we all create code in patterns. I'm attempting to grasp some of the S.O.L.I.D principles and how you put them into practise in the actual world.

I'm having trouble with the letter "D."

I occasionally mix up Dependency Inversion and Dependency Injection. Is this to say that as long as things are based on abstraction (i.e. interfaces), you're good to go?

Is there even a little C# sample somewhere that illustrates it?
Jun 11, 2022 in C# by krishna
• 2,820 points
762 views

1 answer to this question.

0 votes

I am not a specialist like others, but I will attempt to describe DIP in terms of concept. Program to an interface is at the heart of DIP, which means that your high-level classes will rely on abstraction, and your low-level classes will rely on abstraction as well. as an example

Let's imagine you define a PhoneVendor abstraction, which can be anything from Samsung to Apple to Nokia. Sorry for the code; I haven't written Java in a long time, so it may contain grammatical errors, but the concept remains the same.

public abstract class PhoneVendor {

    /**
    * Abstract method that returns a list of phone types that each vendor creates.
    */
    public abstract Vector getPhones(){ }
}


public class Samsung extends PhoneVendor{
    public Vector getPhones(){ // return a list of phones it manufactures...  }
}

public class PhoneFinder{
   private PhoneVendor vendor;

   public PhoneFinder(PhoneVendor vendor){ this.vendor = vendor;}

  /**
   *for example just return a concatnated string of phones
  */
   public string getPhoneTypes(){
      Vector ListOfPhones = PhoneVendor.getPhones();        
      return ListOfPhones;
   }
}

As you can see, the PhoneFinder class is based on the abstraction rather than the PhoneVendor implementation. And the Abstraction is divorced from the high-level classes that use it in your essential classes. This makes the design extremely adaptable, as introducing new Low level classes will not break any previously created code because PhoneFinder is based on abstraction rather than implementation.

answered Jun 14, 2022 by jyoti
• 1,240 points

Related Questions In C#

0 votes
1 answer

Examples of dynamic polymorphism in c#

Check the example of polymorphism below. We ...READ MORE

answered Jun 7, 2022 in C# by pranav
• 2,590 points
876 views
0 votes
1 answer

Which design pattern to use for pre-process process and post-process task

You have pre-defined and precise steps to ...READ MORE

answered Jun 9, 2022 in C# by rajiv
• 1,620 points
1,843 views
0 votes
1 answer

How to implement SOLID principles into an existing project

It will be a lengthy procedure. You ...READ MORE

answered Jun 14, 2022 in C# by krishna
• 2,820 points
583 views
–1 vote
1 answer

Examples of GoF design patterns in .net

I am attaching some links. Go through ...READ MORE

answered Jun 23, 2022 in C# by krishna
• 2,820 points
588 views
0 votes
3 answers

Trying to upload files using Selenium(C#)

You can try using Javascript Executor to ...READ MORE

answered Aug 23, 2019 in Selenium by Abha
• 28,140 points
5,762 views
0 votes
1 answer

Examples of real world big data open source applications

If you are looking for big data ...READ MORE

answered Apr 4, 2018 in Big Data Hadoop by kurt_cobain
• 9,350 points
1,250 views
0 votes
1 answer

How to create excellent examples in R?

An excellent example must consist of the ...READ MORE

answered Apr 10, 2018 in Data Analytics by kappa3010
• 2,090 points

edited Apr 12, 2018 by kappa3010 775 views
0 votes
1 answer

Examples of GoF Design Patterns in Java's core libraries

Observer pattern throughout whole swing (Observable, Observer) MVC also ...READ MORE

answered Jun 27, 2018 in Java by developer_1
• 3,350 points
2,115 views
+1 vote
2 answers

What is an RDBMS? Name some examples for RDBMS? What is CRUD?

RDBMS: Relational Database Management System A relational database ...READ MORE

answered Aug 29, 2018 in Data Analytics by zombie
• 3,790 points
27,952 views
0 votes
1 answer

Examples for string find in Python

you can use str.index too: >>> 'sdfasdf'.index('cc') Traceback ...READ MORE

answered Aug 29, 2018 in Python by Priyaj
• 58,020 points
812 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP