🖋️ 자바 개발 코딩 패턴
목적
Spring Boot 사용법
public interface Animal {
void speak();
}
public class Dog implements Animal {
public void speak() {
System.out.println("Woof");
}
}
public class AnimalFactory {
public static Animal createAnimal(String type) {
if ("dog".equalsIgnoreCase(type)) {
return new Dog();
}
// Add more animals here
throw new IllegalArgumentException("Unknown animal type");
}
}
public class User {
private String firstName;
private String lastName;
private String email;
private User(UserBuilder builder) {
this.firstName = builder.firstName;
this.lastName = builder.lastName;
this.email = builder.email;
}
public static class UserBuilder {
private String firstName;
private String lastName;
private String email;
public UserBuilder setFirstName(String firstName) {
this.firstName = firstName;
return this;
}
public UserBuilder setLastName(String lastName) {
this.lastName = lastName;
return this;
}
public UserBuilder setEmail(String email) {
this.email = email;
return this;
}
public User build() {
return new User(this);
}
}
}
목적
Spring Boot 사용법
목적
Spring Boot 사용법
목적
Spring Boot 사용법
목적
Spring Boot 사용법
목적
Spring Boot 사용법
목적
Spring Boot 사용법
public abstract class DataProcessor {
public void process() {
fetchData();
processData();
saveData();
}
protected abstract void fetchData();
protected abstract void processData();
protected abstract void saveData();
}
public class ConcreteDataProcessor extends DataProcessor {
@Override
protected void fetchData() {
System.out.println("Fetching data...");
}
@Override
protected void processData() {
System.out.println("Processing data...");
}
@Override
protected void saveData() {
System.out.println("Saving data...");
}
}
목적
Spring Boot 사용법
public class UserDTO {
private String name;
private String email;
public UserDTO() {}
public UserDTO(User user) {
this.name = user.getName();
this.email = user.getEmail();
}
// Getters and setters
}