Interview Skills - SOLID principals in 21(ish) seconds

Interview Skills - SOLID principals in 21(ish) seconds

I'm showing my age here, but if like me you remember the 2001 classic "21 seconds" by So Solid Crew, then you know the importance of being able to say a lot in a short amount of time.

Interviewing for Development roles is somewhere that skill can be highly useful, especially when answering questions about SOLID Principals of Object Oriented design, so lets take a few (not 21) seconds to refresh our memories and ensure we can explain these five principals succinctly.


Why are SOLID principals important in interview?

"To create understandable, readable, and testable code that many developers can collaboratively work on."

Essentially, Interviewers are assessing if you join a new team will you be able to understand the existing code base and will you add to it in a way that other Developers will be able to follow your logic.


Let's look at each principle in the SOLID acronym, they are:

  • Single Responsibility Principle
  • Open-Closed Principle
  • Liskov Substitution Principle
  • Interface Segregation Principle
  • Dependency Inversion Principle


The Single Responsibility Principle

The Single Responsibility Principle states that?a class should do one thing and therefore it should have only a single reason to change.

In other words, only one potential change in the specification should be able to affect the specification of the class.

Why is this important?

Multiple teams can work on the same project and edit the same Class for different reasons, this could lead to incompatible modules.

As a bonus, it makes version control much easier and reduces the risk of merge conflicts.


Open-Closed Principle

The Open-Closed Principle requires that?classes should be open for extension and closed to modification.

In other words, you should be able to add new functionality without touching the existing code for the class

Why is this important?

Whenever we modify the existing code, we risk introducing bugs so we should avoid touching production code where possible. Adding functionality through interfaces and abstract ?classes is a much safer option.


Liskov Substitution Principle?

The Liskov Substitution Principle states that subclasses should be substitutable for their base classes.

This means that, given that class B is a subclass of class A, we should be able to pass an object of class B to any method that expects an object of class A and the method should not give any weird output in that case.

Why is this important?

Because when we use inheritance we assume that the child class inherits everything that the superclass has. The child class extends the behavior but never narrows it down.

Therefore, when a class does not obey this principle, it leads to some nasty bugs that are hard to detect.


Interface Segregation Principle

The principle states that many client-specific interfaces are better than one general-purpose interface.

Why is this important?

Clients should not be forced to implement a function they do not need and in doing so they can create complexity that can create problems down the line.

By separating the interfaces the solution is more flexible, extendable while retaining the logic and functionality required.


Dependency Inversion Principle

The Dependency Inversion principle states that our classes should depend upon interfaces or abstract classes instead of concrete classes and functions.

"If the OCP states the goal of OO architecture, the DIP states the primary mechanism".

Why is this important?

This is related to the open-Closed Principal, We want our classes to be open to extension, so we should reorganize our dependencies to depend on interfaces instead of concrete classes.


Conclusion

So hopefully you’ve found that a useful refresher in SOLID Principals that will likely come up in any Software interviews.

By applying them to your own work when developing and refactoring code you’ll create code that’s cleaner, more extendable and testable too, making your life (and your co-workers by extension) that little bit easier.

To paraphrase Romeo Dunn “2 multiplied by 10 plus 1…. Refresher DONE”

要查看或添加评论,请登录

Neill Ferguson的更多文章

  • How to have the Winners Mindset

    How to have the Winners Mindset

    Rodger Federer has gone viral this week after giving a commencement speech at Dartmouth College where he talked about…

    2 条评论
  • Java > Golang - How hard is it?

    Java > Golang - How hard is it?

    You'll be seeing more and more opportunities for Developers with Golang experience, but is the allure of the "dark…

    1 条评论
  • Fundamentals of GIT

    Fundamentals of GIT

    ??Carpenters use hammers ??Mechanics use spanners ?????Developers use GIT Have you noticed that Git is so integral to…

    1 条评论
  • Why Career Direction is more important than Speed

    Why Career Direction is more important than Speed

    Every day on LinkedIn you'll see people celebrating promotions and Career milestones. We've been told for years that…

    1 条评论
  • The Toxicity of "Rise & Grind" culture

    The Toxicity of "Rise & Grind" culture

    Everyday, I see people advocating for "Rise & Grind" mentality as the way to succeed in life: Get up at 5am Gym session…

    2 条评论
  • Is AI coming for your job?

    Is AI coming for your job?

    If there's been one topic I've spoken to Clients and Candidates in 2023, it's the rapid update of Artificial…

    1 条评论
  • Making a move - One day, or Day one?

    Making a move - One day, or Day one?

    In life, timing is everything and at some point you need to choose to turn your "One day" into "Day one". "The…

  • Moving to a new role - Microservices

    Moving to a new role - Microservices

    One of the biggest challenges when moving to a new role is getting used to how the new company "does things". However…

  • Basics - Writing clean code

    Basics - Writing clean code

    Have you ever looked at a piece of code and thought "who on earth wrote this?" and then realised it was you! In…

  • Ace your next interview - using the D.E.N.N.I.S. system

    Ace your next interview - using the D.E.N.N.I.S. system

    I'm a huge fan of Its Always Sunny in Philadelphia, (I was lucky enough to see them live in Dublin a few weeks ago) but…

    2 条评论

社区洞察

其他会员也浏览了