Jump to content
People were interested in these podcasts

SOLID principles…అంత కష్టమా…?


dasari4kntr

Recommended Posts

రెండు interviews..లో ఇద్దరిని అడిగితే …ఇద్దరూ నీళ్ళు నమిలారు…

Link to comment
Share on other sites

  18 hours ago, dasari4kntr said:

రెండు interviews..లో ఇద్దరిని అడిగితే …ఇద్దరూ నీళ్ళు నమిలారు…

Expand  

PM requirement here 

Link to comment
Share on other sites

  18 hours ago, dasari4kntr said:

రెండు interviews..లో ఇద్దరిని అడిగితే …ఇద్దరూ నీళ్ళు నమిలారు…

Expand  

this is the chatGPT answer, ila chebte oknaa, next follow up questions em vuntaayi
 

Great! Let's go over the SOLID principles, which are 5 key design principles in object-oriented programming (OOP) to make software more maintainable, flexible, and scalable.

The acronym SOLID stands for:


S — Single Responsibility Principle (SRP)

"A class should have only one reason to change."

  • Each class or module should focus on one task or responsibility.
  • Benefits: Easier to maintain, test, and understand.
  • Example:
     
    csharp
    CopyEdit
    // Bad: Mixing responsibilities class Report { void GenerateReport() { ... } void SaveToFile() { ... } // Saving is not report generation } // Good: Separate responsibilities class Report { void GenerateReport() { ... } } class FileSaver { void SaveToFile(Report report) { ... } }

O — Open/Closed Principle (OCP)

"Software entities should be open for extension, but closed for modification."

  • You should be able to extend a class's behavior without modifying its source code.
  • Benefits: Easy to add new features without breaking existing code.
  • Example:
     
    csharp
    CopyEdit
    // Base class abstract class Shape { public abstract double GetArea(); } // Extension via inheritance class Circle : Shape { public override double GetArea() { ... } } class Rectangle : Shape { public override double GetArea() { ... } }

L — Liskov Substitution Principle (LSP)

"Derived classes must be substitutable for their base classes."

  • A subclass should be able to replace its parent class without breaking functionality.
  • Benefits: Ensures consistent behavior when using base types.
  • Example:
     
    csharp
    CopyEdit
    class Bird { public virtual void Fly() { ... } } class Sparrow : Bird { public override void Fly() { ... } } // Violating this would be making a Penguin class extend Bird and try to Fly, which it can't.

I — Interface Segregation Principle (ISP)

"Clients should not be forced to depend on interfaces they do not use."

  • Many small, specific interfaces are better than a large, general-purpose one.
  • Benefits: Avoids forcing classes to implement unnecessary methods.
  • Example:
     
    csharp
    CopyEdit
    // Bad: One big interface interface IMachine { void Print(); void Scan(); void Fax(); } // Good: Segregate interfaces interface IPrinter { void Print(); } interface IScanner { void Scan(); } // Class only implements what it needs class Printer : IPrinter { public void Print() { ... } }

D — Dependency Inversion Principle (DIP)

"Depend on abstractions, not on concretions."

  • High-level modules should not depend on low-level modules, but both should depend on abstractions (interfaces).
  • Benefits: Makes code flexible and reduces coupling.
  • Example:
     
    csharp
    CopyEdit
    // Interface interface IMessageSender { void SendMessage(string message); } // Concrete implementation class EmailSender : IMessageSender { public void SendMessage(string message) { ... } } // High-level class depending on abstraction class NotificationService { private readonly IMessageSender _sender; public NotificationService(IMessageSender sender) { _sender = sender; } public void Notify(string message) { _sender.SendMessage(message); } }

Summary of SOLID:

Principle Description Goal
S - Single Responsibility One class = one job Low coupling, high cohesion
O - Open/Closed Open for extension, closed for modification Extensible and stable code
L - Liskov Substitution Subtypes replace base types without issues Reliable polymorphism
I - Interface Segregation Many specific interfaces > one large one Avoid bloated interfaces
D - Dependency Inversion Depend on abstractions, not concretions Flexible, testable, maintainable code
Link to comment
Share on other sites

  18 hours ago, dasari4kntr said:

రెండు interviews..లో ఇద్దరిని అడిగితే …ఇద్దరూ నీళ్ళు నమిలారు…

Expand  

SOLID principles kakunda inkem telsikovaali ?? For interviews??

Link to comment
Share on other sites

  18 hours ago, Spartan said:

frankly....interviews ki tappa...real world daily work lo does anyone even care about these anna..

SOLID, ACID... etc

vatillo unna concepts over the period experience to ostai....but desining or coding appudu I havent seen anyone bring this up and adhere to them..

unless someone wants to play Devils Advocate during the session....

@Konebhar6 @dasari4kntr @csrcsr

Expand  

code reviews lo chustam anna

Link to comment
Share on other sites

  18 hours ago, EggpuffReddy said:

this is the chatGPT answer, ila chebte oknaa, next follow up questions em vuntaayi
 

Great! Let's go over the SOLID principles, which are 5 key design principles in object-oriented programming (OOP) to make software more maintainable, flexible, and scalable.

The acronym SOLID stands for:


S — Single Responsibility Principle (SRP)

"A class should have only one reason to change."

  • Each class or module should focus on one task or responsibility.
  • Benefits: Easier to maintain, test, and understand.
  • Example:
     
    csharp
    CopyEdit
    // Bad: Mixing responsibilities class Report { void GenerateReport() { ... } void SaveToFile() { ... } // Saving is not report generation } // Good: Separate responsibilities class Report { void GenerateReport() { ... } } class FileSaver { void SaveToFile(Report report) { ... } }

O — Open/Closed Principle (OCP)

"Software entities should be open for extension, but closed for modification."

  • You should be able to extend a class's behavior without modifying its source code.
  • Benefits: Easy to add new features without breaking existing code.
  • Example:
     
    csharp
    CopyEdit
    // Base class abstract class Shape { public abstract double GetArea(); } // Extension via inheritance class Circle : Shape { public override double GetArea() { ... } } class Rectangle : Shape { public override double GetArea() { ... } }

L — Liskov Substitution Principle (LSP)

"Derived classes must be substitutable for their base classes."

  • A subclass should be able to replace its parent class without breaking functionality.
  • Benefits: Ensures consistent behavior when using base types.
  • Example:
     
    csharp
    CopyEdit
    class Bird { public virtual void Fly() { ... } } class Sparrow : Bird { public override void Fly() { ... } } // Violating this would be making a Penguin class extend Bird and try to Fly, which it can't.

I — Interface Segregation Principle (ISP)

"Clients should not be forced to depend on interfaces they do not use."

  • Many small, specific interfaces are better than a large, general-purpose one.
  • Benefits: Avoids forcing classes to implement unnecessary methods.
  • Example:
     
    csharp
    CopyEdit
    // Bad: One big interface interface IMachine { void Print(); void Scan(); void Fax(); } // Good: Segregate interfaces interface IPrinter { void Print(); } interface IScanner { void Scan(); } // Class only implements what it needs class Printer : IPrinter { public void Print() { ... } }

D — Dependency Inversion Principle (DIP)

"Depend on abstractions, not on concretions."

  • High-level modules should not depend on low-level modules, but both should depend on abstractions (interfaces).
  • Benefits: Makes code flexible and reduces coupling.
  • Example:
     
    csharp
    CopyEdit
    // Interface interface IMessageSender { void SendMessage(string message); } // Concrete implementation class EmailSender : IMessageSender { public void SendMessage(string message) { ... } } // High-level class depending on abstraction class NotificationService { private readonly IMessageSender _sender; public NotificationService(IMessageSender sender) { _sender = sender; } public void Notify(string message) { _sender.SendMessage(message); } }

Summary of SOLID:

Principle Description Goal
S - Single Responsibility One class = one job Low coupling, high cohesion
O - Open/Closed Open for extension, closed for modification Extensible and stable code
L - Liskov Substitution Subtypes replace base types without issues Reliable polymorphism
I - Interface Segregation Many specific interfaces > one large one Avoid bloated interfaces
D - Dependency Inversion Depend on abstractions, not concretions Flexible, testable, maintainable code
Expand  

next ఆ dependecy invesion గురించి  questions పడతాయి…

Link to comment
Share on other sites

  18 hours ago, Spartan said:

frankly....interviews ki tappa...real world daily work lo does anyone even care about these anna..

SOLID, ACID... etc

vatillo unna concepts over the period experience to ostai....but desining or coding appudu I havent seen anyone bring this up and adhere to them..

unless someone wants to play Devils Advocate during the session....

@Konebhar6 @dasari4kntr @csrcsr

Expand  

solid …very important…

if someone knows…solid …they know the dependency injection….and  next they kbow how it is useful in unit tests…

  • Sad 1
Link to comment
Share on other sites

  18 hours ago, Spartan said:

frankly....interviews ki tappa...real world daily work lo does anyone even care about these anna..

SOLID, ACID... etc

vatillo unna concepts over the period experience to ostai....but desining or coding appudu I havent seen anyone bring this up and adhere to them..

unless someone wants to play Devils Advocate during the session....

@Konebhar6 @dasari4kntr @csrcsr

Expand  

simple example…springboot లో ప్రతి class లో @Autowired  అని రాస్తాం…అది ఎందుకు అంటే…దానికి ఆది మూలం ఇదే…

Link to comment
Share on other sites

  18 hours ago, *Prince Charming said:

SOLID principles kakunda inkem telsikovaali ?? For interviews??

Expand  

developer role కాబట్టి …అక్కడ నుండి start చేసా…next…oka coding problem ఇచ్చి execute చేయమంటా…to see he is hands on or not…

Link to comment
Share on other sites

  18 hours ago, dasari4kntr said:

రెండు interviews..లో ఇద్దరిని అడిగితే …ఇద్దరూ నీళ్ళు నమిలారు…

Expand  

Kanikaram ledhu e khatina manavudiki

  • Haha 2
Link to comment
Share on other sites

  18 hours ago, Spartan said:

frankly....interviews ki tappa...real world daily work lo does anyone even care about these anna..

SOLID, ACID... etc

vatillo unna concepts over the period experience to ostai....but desining or coding appudu I havent seen anyone bring this up and adhere to them..

unless someone wants to play Devils Advocate during the session....

@Konebhar6 @dasari4kntr @csrcsr

Expand  

Acid yes…. Solid jujubi mostly

intervieer thana pethapam chupimchalante aduguthadu ilantivi .. kondharu ithe  java lantivi ok but thuppasi vatiki kuda VERSIONS adugutharu

Link to comment
Share on other sites

sare.. @Spartan @Mr Mirchi...ee code ki unit test ela raastro.. cheppandi....

class OrderService {
    private final SqlDatabase database; 
    private final FileLogger logger;    

    public OrderService() {
        this.database = new SqlDatabase(); 
        this.logger = new FileLogger();    
    }

    public void processOrder(Order order) {
        try {
            database.save(order);
            logger.log("Order processed: " + order.getId());
        } catch (Exception e) {
            logger.log("Error processing order: " + e.getMessage());
        }
    }
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...