Collection
- 데이터들을 모아서 가지고 있는 자료구조
Generic
- Collection이 가지고 있는 데이터들의 데이터 타입을 지정
- Generic 기법을 사용한 코드가 그렇지 않은 코드보다 훨씬 간결하고 보기편함.
Generic 기법 사용(x)
class Circle{} class Square{} class SquareSlot{ insert(Square sqareSlot){ } } class CircleSlot{ insert(Circle circleSlot){ } } void main(){ var circleSlot = new CircleSlot(); circleSlot.insert(new Circle()); var squareSlot = new SquareSlot(); squareSlot.insert(new Square()); }
Generic 기법 사용(o)
void main(){ var circleSlot = new Slot<Circle>(); circleSlot.insert(new Circle()); var squareSlot=new Slot<Square>(); squareSlot.insert(new Square()); } class Circle{} class Square{} class Slot<T>{ insert(T shape){ } }
'ETC > Flutter' 카테고리의 다른 글
[flutter] Future 와 async를 사용해보자. (0) | 2021.10.17 |
---|---|
[flutter] Future란 무엇인가? (3) | 2021.10.17 |
[flutter] const와 final의 특징 (0) | 2021.10.17 |
[flutter] Stateful Widget 과 Stateless Widget 의 차이점 (0) | 2021.10.17 |
[flutter] pushNamed를 활용한 navigator 사용법. (0) | 2021.10.17 |
[flutter] widget 이란? (0) | 2021.10.17 |
댓글