Filter
Exclude
Time range
-
Near
Replying to @SumitM_X
This class is doing too much. • generate → business logic • saveToDb → persistence • sendEmail → communication Split it using Single Responsibility Principle: ReportGenerator ReportRepository NotificationService Smaller classes = easier to test, change, and scale. One class → one reason to change.
2
29
5,415
Replying to @SumitM_X
I would explain to the junior like so: We can think of this intuitively. A report object irl would be a piece of paper. If this Report was real, it would be a magic paper. Can a paper file itself into a cabinet and mail itself to a client? no, separate people handle that. Same can be applied here. Split it up. Saving to db goes to repository layer, sending mail goes to a notification service, and generation logic goes to something like a ReportGenerator. The Report class itself should just hold the report data.
1
1
33
9,436
Is this really “clean”? class ReportGenerator { public String generateReport() { ... } public void exportToPdf() { ... } public void saveToFile() { ... } } Generating ≠ Exporting ≠ Persisting. What happens when we add CSV export next week? #SoftwareEngineering
4
16
2,550
Replying to @javarevisited
It breaks the Open/Closed principle since adding a new report would change the class. I would suggest to change the class into an interface and create classes based on the types: class PdfReportGenerator implements ReportGenerator { void generate(); }
5
1,242
Which principle is this class breaking? class ReportGenerator { void generate(String type) { if ("PDF".equals(type)) { // generate pdf } else if ("EXCEL".equals(type)) { // generate excel } else if ("HTML".equals(type)) { // generate html } } } Hint: What happens when you add a new format? 🤔
14
1
30
16,244
Replying to @SumitM_X
This class is violating the Single Responsibility Principle (SRP); it's handling report generation, database persistence, and email notifications all in one place. I suggest breaking it into separate components: -> ReportGenerator (core logic) -> ReportRepository (data layer) -> NotificationService (email/communication)
4
3,464
Replying to @SumitM_X
This class has too many responsibilities: generating, persisting, and notifying. This violates the Single Responsibility Principle. A better design would be: - ReportGenerator - ReportRepository - ReportNotifier This change is justified for each class. Clean architecture isn’t about adding more classes; it’s about clarifying responsibilities.
1
1
11
4,777
Replying to @SumitM_X
I will tell him this class is doing too many things and will become hard to maintain later. Right now Report is: - generating data - handling database persistence - sending emails These are three different responsibilities. I will suggest following the Single Responsibility Principle and separating concerns: ReportGenerator= handles report creation ReportRepository = saves report to DB ReportEmailService = sends email The Report class should ideally just represent the data/model, not the actions around it. This separation makes the code easier to test, modify, and extend without breaking unrelated functionality.
14
10,194
📀 DATA BECKER präsentiert: Superbase – die professionelle Datenbank für den Commodore 64 und Apple IIe/IIc! 127 Felder, 1108 Zeichen, Reportgenerator – und das alles auf Diskette. Datenbankpower für Heimcomputer! 💾 #C64 #AppleII #DataBecker #RetroComputing #Superbase
6
155
Every backend engineer should know the SOLID principles. They’re not buzzwords. They’re the difference between code that’s flexible and code that traps you. Here’s the breakdown in simple words : 1. Single Responsibility Principle (SRP) A class should only do one thing. If a UserService handles login, DB writes, and sending emails, that class becomes impossible to change safely. Break responsibilities apart: AuthService, UserRepository, EmailService. 2. Open/Closed Principle (OCP) Your code should be easy to extend without rewriting old logic. For example, if you have a ReportGenerator, you shouldn’t edit it every time a new format (PDF, Excel, CSV) is added. Instead, design it so you can just plug in new report types. Old code stays untouched. 3. Liskov Substitution Principle (LSP) If class B inherits from class A, it should work wherever A is expected. If Bird has a fly() method, but you add Penguin and it throws an error, your inheritance is broken. Subclasses must not violate the expectations set by their parent. 4. Interface Segregation Principle (ISP) Don’t force classes to implement methods they don’t need. If a Printer interface has print(), scan(), fax(), and staple(), then a basic printer is stuck with meaningless code. Instead, split it into smaller, focused interfaces (Printable, Scannable, etc.). 5. Dependency Inversion Principle (DIP) Depend on abstractions, not concrete classes. If your checkout system is hardwired to PayPal, you’re locked in. By depending on a PaymentProcessor interface, you can swap PayPal for Stripe (or any other provider) without touching core logic. Why this matters Anyone can write code that works. SOLID helps you write code that lasts. Code that’s easier to test, extend, and maintain as your system and team grow.
2
27
1,154
✅Open/Closed Principle (OCP): OCP is a SOLID principle that states classes should be open for extension but closed for modification. Instead of touching existing implementation, you should use Java interfaces and inheritance to add new behavior. Examples: ❌ A bad way to implement a report generator: class ReportGenerator { public void generateReport(String type) { if (type.equals("PDF")) { System.out.println("Generating PDF Report..."); } else if (type.equals("CSV")) { System.out.println("Generating CSV Report..."); } else if (type.equals("EXCEL")) { System.out.println("Generating Excel Report..."); } } } ✅ A better way: //Define an interface interface Report { void generate(); } //Define implementations class PdfReport implements Report { public void generate() { System.out.println("Generating PDF Report..."); } } class CsvReport implements Report { public void generate() { System.out.println("Generating CSV Report..."); } } //Use a specific implementation public class ReportApp { public static void main(String[] args) { Report report = new PdfReport(); report.generate(); } } #Java #SOLIDPrinciples
5
7
76
4,372
Kommt bald in #Ekahau #AIPO; ein einfach zu nutzender Reportgenerator. #wifidesignday
1
2
272
Let's understand in details:👇👇 1. S - Single Responsibility Principle (SRP)Definition: A class should have only one reason to change, meaning it should have only one responsibility. Example: ✅ A ReportGenerator class should only generate reports, while a ReportPrinter class should handle printing. ❌ A ReportManager class that both generates and prints reports violates SRP. 2. O - Open/Closed Principle (OCP)Definition: A class should be open for extension but closed for modification. Example: ✅ Instead of modifying an existing class, create a new subclass or use polymorphism. ❌ Editing a class every time a new feature is needed violates OCP. 3. L - Liskov Substitution Principle (LSP)Definition: Subclasses should be replaceable for their base class without altering program correctness. Example: ✅ If Rectangle is a base class and Square is its subclass, overriding the behavior incorrectly should not break functionality. ❌ If Square changes how Rectangle works unexpectedly, it violates LSP. 4. I - Interface Segregation Principle (ISP)Definition: A class should not be forced to implement interfaces it does not use. Example: ✅ Have multiple smaller interfaces like Printable and Scannable instead of one big Machine interface with unrelated methods. ❌ Forcing a class to implement unnecessary methods from a large interface violates ISP. 5. D - Dependency Inversion Principle (DIP)Definition: High-level modules should not depend on low-level modules. Both should depend on abstractions. Example: ✅ Use dependency injection, where classes depend on abstractions (interfaces) instead of concrete implementations. ❌ If a class directly instantiates objects (new keyword in Java, C#), it violates DIP.
1
4
632
21 Aug 2024
Replying to @5eniorDeveloper
Yo tengo una clase en un sistema que genera reportes. ReportGenerator se llama si mal no recuerdo. Tranquilamente la clase tiene como 20k loc. Por ese sistema pasan diariamente como unos 10-20M mxn durante los últimos 11 años. Ahí sigue la cochinada y sin vistos de que lo cambien
1
3
903
I like ReportGenerator because it supports multiple input and output formats, it can combine outputs from multiple test projects (e.g. unit and integration tests), it's free and open source, and it integrates nicely with Azure DevOps. bit.ly/3TPpp1r #devops #tdd #azure
2
12
1,141
Replying to @mjovanovictech
Not particularly a library, but ReportGenerator may be useful to generate code coverage reports: github.com/danielpalme/Repor…
2
24
2,857
3 Apr 2024
Coverletでコードカバレッジ計測してReportGeneratorでレポートにするやつやってみたらこんな感じで表示できてすごーい!ってなった learn.microsoft.com/ja-jp/do…
1
1
163