💡 일반적으로 REST API에서는 클라이언트로 응답할 데이터를 JSON 또는 XML 형식으로 변환하여 ResponseEntity 객체에 담아서 반환한다.
💡 ResponseEntity 객체는 HTTP 응답 코드, 응답 헤더, 응답 바디 등을 포함하고 있다.
// Animal 인터페이스
public interface Animal {
void makeSound();
}
// Cat 클래스, Animal 인터페이스를 구현
public class Cat implements Animal {
@Override
public void makeSound() {
System.out.println("Meow");
}
}
// Dog 클래스, Animal 인터페이스를 구현
public class Dog implements Animal {
@Override
public void makeSound() {
System.out.println("Woof");
}
}
// AnimalFactory 클래스, Animal 객체를 생성하여 반환하는 팩토리 클래스
public class AnimalFactory {
public static Animal getAnimal(String animalType) {
if (animalType == null) {
return null;
}
if (animalType.equalsIgnoreCase("CAT")) {
return new Cat();
} else if (animalType.equalsIgnoreCase("DOG")) {
return new Dog();
}
return null;
}
}
// Main 클래스
public class Main {
public static void main(String[] args) {
// 팩토리를 사용하여 Animal 객체 생성
Animal cat = AnimalFactory.getAnimal("cat");
Animal dog = AnimalFactory.getAnimal("dog");
// Animal 객체의 메서드 호출
cat.makeSound(); // 출력: Meow
dog.makeSound(); // 출력: Woof
}
}
@startuml
title Class Diagram for User Management
class UserController {
+ createUser()
+ getUser()
+ updateUser()
+ deleteUser()
}
class UserService {
- userRepository: UserRepository
+ createUser()
+ getUser()
+ updateUser()
+ deleteUser()
}
interface UserRepository {
+ createUser()
+ getUser()
+ updateUser()
+ deleteUser()
}
class UserEntity {
- id: Long
- name: String
- email: String
- password: String
+ getId()
+ getName()
+ getEmail()
+ getPassword()
+ setId()
+ setName()
+ setEmail()
+ setPassword()
}
class UserDto {
- id: Long
- name: String
- email: String
+ getId()
+ getName()
+ getEmail()
+ setId()
+ setName()
+ setEmail()
}
UserController -> UserService
UserService -> UserRepository
UserService -> UserEntity
UserController -> UserDto
UserService -> UserDto
UserRepository -> UserEntity
UserRepository -> UserDto
@enduml
그외 객체..