class Company{
String name='';
Person ceo = new Person("ceo");
List<Person> workerList = [];
Company(String this.name);
void setCeo(Person ceo){
this.ceo = ceo;
}
void addWorker(Person worker){
this.workerList.add(worker);
}
void removeWorker(Person worker){
this.workerList.remove(worker);
}
void info(){
print('company : $name');
this.ceo.info();
this.workerList.forEach( (e){
print(e.name);
});
for(int i=0; i<this.workerList.length; i++){
print(this.workerList[i].name);
}
for(Person e in workerList){
print(e.name);
}
//print('ceo : ${this.ceo.name}');
}
}
class Person{
String name='';
Person(String this.name);
void info(){
print(name);
}
}
void main(){
Person pa = new Person("ceo영희");
Person pb = new Person("ceo길동");
Person pc = new Person("태현");
Person pd = new Person("소리");
pa.info();
pb.info();
String aaName = "aa";
Company aa = new Company(aaName);
Company bb = new Company("bb");
aa.addWorker(pc);
aa.addWorker(pd);
aa.removeWorker(pc);
aa.setCeo(pa);
bb.setCeo(pb);
aa.info();
bb.info();
}
'IT News > Flutter & Dart' 카테고리의 다른 글
Dart 클래스를 사용한 리스트 구현 (0) | 2021.09.06 |
---|---|
함수(function)와 메쏘드(method)의 차이점 (0) | 2021.08.27 |
다트(dart) 기본 변수값 출력 $ {} 사용법 (0) | 2021.08.27 |