Re: [問題] 新手繼承問題(非作業)
Just some suggestions...
1. The Person class should be abstract, so your sub-classess
can inherit all characters from parent class without distroying data.
2. Because you have private fields in your parent classes,
you should have "gettters" for each variables. In you codes,
you only have getter for name, not ID. What happen if you only need
ID?
3. In the theory of inheritace on JAVA language, you can say
a "student" is a person. Therefore, you can just create a new student
instance, without create a person instance. That is another reason you
have a abstract class for person because every student is a person.
4. In program design of reality, It's much better if you use methods in
printing information. It means you only call other methods when you want
to output some information, so you just need to modity your information
resource method rather than print method. It helps your program become
scalable and flexible.
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 27.252.20.46
※ 編輯: pelicanper 來自: 27.252.20.46 (10/20 17:45)
推
10/20 22:04, , 1F
10/20 22:04, 1F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 4 篇):