# 01 스프링 등장 배경, 객체지향

p11

```java
// 두 개의 정수를 더하는 메서드
public int add(int a, int b) {
    return a + b;
}

// 세 개의 정수를 더하는 메서드 (오버로딩)
public int add(int a, int b, int c) {
    return a + b + c;
}

```

p11

```java
// 부모 클래스
public class Animal {
    // 부모 클래스의 메서드
    public void sound() {
        System.out.println("The animal makes a sound");
    }
}

// 자식 클래스 1: Dog
public class Dog extends Animal {
    @Override
    public void sound() {
        System.out.println("The dog barks");
    }
}

```

p14

```java
// 단일 책임 원칙을 위반한 클래스
public class Employee {
    public void calculateSalary() {
        // 급여 계산 로직
    }

    public void generateReport() {
        // 리포트 생성 로직
    }
}

```

p14

```java
public class Employee {
    public void calculateSalary() {
        // 급여 계산 로직
    }
}

public class ReportGenerator {
    public void generateReport() {
        // 리포트 생성 로직
    }
}

```

p15

```java
// 개방-폐쇄 원칙을 위반한 코드
public class Rectangle {
    public double length;
    public double width;
}

public class AreaCalculator {
    public double calculateRectangleArea(Rectangle rectangle) {
        return rectangle.length * rectangle.width;
    }
}

```

p15

```java
// 도형 인터페이스 정의
public interface Shape {
    double calculateArea();
}

public class Rectangle implements Shape {
    public double length;
    public double width;

    public Rectangle(double length, double width) {
        this.length = length;
        this.width = width;
    }

    @Override
    public double calculateArea() {
        return length * width;
    }
}

```

p15

```java
public class AreaCalculator {
    public double calculateArea(Shape shape) {
        return shape.calculateArea();
    }
}

```

p16

```java
public class Bird {
    public void fly() {
        System.out.println("Flying");
    }
}

public class Penguin extends Bird {
    @Override
    public void fly() {
        throw new UnsupportedOperationException("Penguins cannot fly");
    }
}

```

p16

```java
public class Bird {
    public void move() {
        System.out.println("Moving");
    }
}

public class FlyingBird extends Bird {
    public void fly() {
        System.out.println("Flying");
    }
}

public class Penguin extends Bird {
    @Override
    public void move() {
        System.out.println("Penguin is walking");
    }
}

```

p17

```java
public interface Worker {
    void work();
    void eat();
}

public class Robot implements Worker {
    @Override
    public void work() {
        System.out.println("Robot working");
    }

    @Override
    public void eat() {
        // 로봇은 먹지 않음. 불필요한 메서드.
    }
}

```

p17

```java
public interface Workable {
    void work();
}

public interface Eatable {
    void eat();
}

public class Robot implements Workable {
    @Override
    public void work() {
        System.out.println("Robot working");
    }
}

```

p18

```java
public class Light {
    public void turnOn() {
        System.out.println("Light turned on");
    }
}

public class Switch {
    private Light light;

    public Switch(Light light) {
        this.light = light;
    }

    public void operate() {
        light.turnOn();
    }
}

```

p18

```java
public interface Switchable {
    void turnOn();
}

public class Light implements Switchable {
    @Override
    public void turnOn() {
        System.out.println("Light turned on");
    }
}

public class Switch {
    private Switchable device;

    public Switch(Switchable device) {
        this.device = device;
    }

    public void operate() {
        device.turnOn();
    }
}

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://team-everywhere.gitbook.io/backend/spring/spring-boot/01.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
