package CHAPTER09;

import java.util.List;

//부모 클래스: Shape
class Shape {
	public void draw() {
		System.out.println("Drawing a shape");
	}
}

//자식 클래스: Circle
class Circle extends Shape {
	@Override
	public void draw() {
		System.out.println("Drawing a circle");
	}
}

//자식 클래스: Rectangle
class Rectangle extends Shape {
	@Override
	public void draw() {
		System.out.println("Drawing a rectangle");
	}
}

public class C9_07_WildCardInheritance {
	
	// 상한 제한 와일드카드: Shape 또는 그 하위 클래스만 허용
	public static void drawShapes(List<? extends Shape> shapes) {
		for (Shape shape : shapes) {
			shape.draw(); // Shape 타입으로 안전하게 사용 가능
		}
	}

	public static void main(String[] args) {
		// Circle 객체로 구성된 리스트
		List<Circle> circles = List.of(new Circle(), new Circle());

		// Rectangle 객체로 구성된 리스트
		List<Rectangle> rectangles = List.of(new Rectangle(), new Rectangle());

		// drawShapes 메서드 호출
		drawShapes(circles); // 출력: Drawing a circle, Drawing a circle
		drawShapes(rectangles); // 출력: Drawing a rectangle, Drawing a rectangle
	}
}
