-
class 다루기 #7 interface 인터페이스프로그래밍 공부 메모/flutter 2022. 5. 17. 21:52
1. dart언어에선 인터페이스 클래스를 만들시 관련 키워드가 따로없다
2. 인터페이스는 사용하고자 하는 변수, 함수 등을 이름과 타입만 선언해준다
3. 인터페이스의 변수와 함수는 꼭 "implements" 강제로 구현을 해줘야한다
4. 코드 작성시 클래스의 상속, 오버라이딩을 통해 해결할 수 있다면 굳이 인터페이스를 사용하지 않아도 된다
5. 부모로 부터 상속받은 클래스는 변수,함수를 사용하든 말든 상관없지만 인터페이스는 꼭 구현을 통한 강제성이 있다
6. abstract 키워드를 추가( ' abstract class IdolInterface{ } ' ) 하여 혹시나 인터페이스를 인스턴스화 할 가능성을 막을 수 있다
=> IdolInterface test = new IdolInterface() ×
void main() { BoyGroup bts = new BoyGroup('BTS'); bts.sayName(); } // interface class IdolInterface{ String? name; void sayName(){} } class BoyGroup implements IdolInterface{ String? name; BoyGroup(String name,) : this.name = name; void sayName(){ print('제 이름은 ${this.name} 입니다'); } }
반응형'프로그래밍 공부 메모 > flutter' 카테고리의 다른 글
List 다루기 Looping / Mapping / Reduce / Fold (0) 2022.05.17 class 다루기 #8 Cascade Operator (0) 2022.05.17 class 다루기 #6 super / this 언제 써야 하나? (0) 2022.05.17 class 다루기 #5 static 키워드 (0) 2022.05.17 class 다루기 #4 overriding 오버라이딩(덮어쓰기) (0) 2022.05.16