View DogHouse.java
import java.time.LocalDate; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Random; | |
public class DogHouse { | |
public List<Dog> dogs = new ArrayList<>(); | |
public String deposit(String userName, Dog dog) { | |
String validationMessage = ""; |
View middleMan.java
class Manager { | |
Worker worker; | |
void doThing() { | |
worker.doThing(); | |
} | |
void doAnotherThing() { | |
worker.doAnotherThing(); | |
} |
View messageChains.java
// As a direct chain of calls | |
class FlightBooking { | |
// ... | |
private boolean isSeatAvailable(int rowNumber, String seat) { | |
return this.plane.getRow(rowNumber).isAvailable(seat); | |
} | |
} | |
// Chaining calls through intermediate results |
View featureEnvy.java
// From Ayush Jindal's exercises for code smells https://github.com/ayjindal/CodeSmells | |
public class Address { | |
private String addressLine1; | |
private String addressLine2; | |
private String city; | |
private String state; | |
private String country; | |
private String postalCode; |
View nullCheck.java
// Adapted from Code Smell: Null Check, Joe Eames https://medium.com/thinkster-io/code-smell-null-check-a0c4851fafbf | |
class DiscountCalculator { | |
// ... | |
public float getDiscount(String customerId) { | |
Customer customer = customerRepository.findBy(customerId); | |
if(customer == null) { | |
return DEFAULT_DISCOUNT; | |
} |
View caseStatement.java
// From Code Smells – Part II, Ana Nogal https://www.ananogal.com/blog/code-smells-part-two/ | |
public enum EmployeeType { | |
Worker, | |
Supervisor, | |
Manager | |
} | |
public class Employee { | |
private float salary; |
View alternativeClasses.java
// From Fixing Object oriented abusers, Manh Phan https://ducmanhphan.github.io/2020-01-24-Fixing-object-oriented-abusers/ | |
public class CheckoutHanlder { | |
// ... | |
public double convertToCurrency(double price, String currencyTo) { | |
if (currencyTo.equalsIgnoreCase("EUR")) { | |
return price * 0.9; | |
} else if (currencyTo.equalsIgnoreCase("CAD")) { | |
return price * 1.35; |
View CoffeeBuilder.java
package coffee_shop.menu.beverages_builders; | |
import coffee_shop.Beverage; | |
public interface CoffeeBuilder { | |
Beverage make(); | |
CoffeeBuilder withMilk(); | |
CoffeeBuilder withCream(); | |
CoffeeBuilder withCinnamon(); | |
} |
View HotChocolateBuilder.java
package coffee_shop.menu.beverages_builders; | |
import coffee_shop.Beverage; | |
public interface HotChocolateBuilder { | |
Beverage make(); | |
HotChocolateBuilder withCream(); | |
HotChocolateBuilder withCinnamon(); | |
} |
View TeaBuilder.java
package coffee_shop.menu.beverages_builders; | |
import coffee_shop.Beverage; | |
public interface TeaBuilder { | |
Beverage make(); | |
TeaBuilder withMilk(); | |
TeaBuilder withCinnamon(); | |
} |
NewerOlder