11<?xml version =" 1.0" encoding =" UTF-8" ?>
22<system-prompt xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
3- xsi : noNamespaceSchemaLocation =" system-prompt .xsd"
3+ xsi : noNamespaceSchemaLocation =" spml .xsd"
44 id =" 121-java-object-oriented-design" version =" 1.0" >
55 <metadata >
66 <description >Java Object-Oriented Design Guidelines</description >
4444class UserData {
4545 private String name;
4646 private String email;
47-
48- public UserData(String name, String email) {
49- this.name = name;
50- this.email = email;
47+
48+ public UserData(String name, String email) {
49+ this.name = name;
50+ this.email = email;
5151 }
52-
52+
5353 public String getName() { return name; }
5454 public String getEmail() { return email; }
5555}
@@ -141,25 +141,25 @@ class Car {
141141 System.out.print(modelName + ": ");
142142 engine.stop();
143143 }
144-
144+
145145 public String getModelName() { return modelName; }
146146}]]> </code-block >
147147 </good-example >
148148 <bad-example >
149149 <code-block language =" java" ><![CDATA[ // Bad: Tight coupling, not programming to an interface
150150class BadCar {
151151 private final BadPetrolEngine engine; // Direct dependency on concrete BadPetrolEngine
152-
152+
153153 public BadCar() {
154154 this.engine = new BadPetrolEngine(); // Instantiates concrete class
155155 }
156-
156+
157157 public void start() { engine.startPetrol(); }
158158 // If we want an electric car, this class needs significant changes or a new similar class.
159159}
160160
161- class BadPetrolEngine {
162- public void startPetrol() { System.out.println("Bad petrol engine starts."); }
161+ class BadPetrolEngine {
162+ public void startPetrol() { System.out.println("Bad petrol engine starts."); }
163163}]]> </code-block >
164164 </bad-example >
165165 </code-examples >
@@ -220,7 +220,7 @@ class BadBankAccount {
220220 this.accountNumber = accountNumber;
221221 this.balance = initialBalance; // No validation
222222 }
223-
223+
224224 // No methods to control access or validate operations
225225}
226226
@@ -270,7 +270,7 @@ class OrderCalculator {
270270
271271class OrderValidator {
272272 public boolean isValid(Order order) {
273- return !order.getItems().isEmpty() &&
273+ return !order.getItems().isEmpty() &&
274274 order.getCustomer() != null &&
275275 order.getCustomer().hasValidPaymentMethod();
276276 }
@@ -300,11 +300,11 @@ class OrderManager {
300300 public void generateInvoice() { /* ... */ }
301301 public void trackShipment() { /* ... */ }
302302 // ... many more methods
303-
303+
304304 // This class has too many responsibilities and reasons to change
305305}]]> </code-block >
306306 </bad-example >
307307 </code-examples >
308308 </rule-section >
309309 </content-sections >
310- </system-prompt >
310+ </system-prompt >
0 commit comments