Urgent.News

What's breaking now, across thousands of outlets.

Tech

S — Single Responsibility Principle — SOLID Principles with Examples

Lesson 1 of 8 in the free SOLID Principles with Examples course on DevLadder. "A class should have one, and only one, reason to change." — Robert C. Martin "Reason to change" = one actor or stakeholder. A class that formats invoices and saves them and emails them changes when finance, DBAs or the email provider change. // ❌ Violates SRP — three reasons to change public class InvoiceService {…

The Single Responsibility Principle (SRP) asserts that a class should possess only one reason to change. This implies that each class should have one cohesive job, with no more than one compelling motive for alteration. Changing the class responsible for formatting invoices, saving them, and emailing them simultaneously violates SRP. Altering the invoice formatting method, the data storage mechanism, or the email delivery service would all necessitate modifications to the class.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Class, object, fields, properties and methods — OOP Concepts in C#

Lesson 1 of 15 in the free OOP Concepts in C# course on DevLadder. A class is a blueprint; an object is an instance created from it at runtime.

  • A class is a blueprint for objects in C#, likened to a template.
  • Objects are instances of classes generated at runtime with their own state.
  • Encapsulation safeguards class data by making fields private and providing public access methods.

What a Successful Code Scan Does Not Prove

Quick answer: A successful scan proves the document was rebuilt from routes the scan could resolve, and nothing more. It does not prove the implementation conforms to the spec, behaves correctly at…

Singleton — Design Patterns (GoF + Enterprise) in C#

Lesson 1 of 18 in the free Design Patterns (GoF + Enterprise) in C# course on DevLadder. Ensure a class has one instance with a global access point.

  • Singleton ensures single instance with global access in C#
  • Implement sealed class, private constructor, Lazy<T> for thread safety
  • ASP.NET Core uses services.AddSingleton T for Singleton management

More from Sunday 8 November →