Computer Science Canada [Source Code] HighScoreList class |
Author: | Aziz [ Mon Jun 27, 2005 1:34 am ] | ||
Post subject: | [Source Code] HighScoreList class | ||
Hey I wrote this yesterday and today. Got the idea from my Turing module, but this ones kinda different ![]() ![]()
|
Author: | wtd [ Mon Jun 27, 2005 1:40 am ] |
Post subject: | |
Now rewrite it much shorter by subclassing something like ArrayList. ![]() |
Author: | Aziz [ Mon Jun 27, 2005 9:37 am ] |
Post subject: | |
If I knew how and new what subclassing mean I would ![]() *Still java n00b* |
Author: | wtd [ Mon Jun 27, 2005 2:37 pm ] | ||||||||
Post subject: | |||||||||
I'm talking about inheritance. "Is a" relationships. Code reuse. ![]() You're creating a list class, right? So each object of that class is going to be a list. Well, we already have basic list classes, so why not inherit from those and get all of the list functionality "for free"? Consider a simple example: my classic Name class.
Now, what if I want a name class that has a title? We'll call it "FormalName". Well, I would copy and paste and write an entirely new class.
Or, I could use inheritance and make FormalName a subclass of Name.
Now, to take this a bit further...
And now since a FormalName is a Name, anywhere I have a method that takes a Name as a parameter, I can give it a FormalName, or a DoctorsName. |
Author: | Aziz [ Mon Jun 27, 2005 3:03 pm ] |
Post subject: | |
Would that be possible for this? My highscore list has 2 lists...names and scores, or is there another way, oh great Dark Master? |
Author: | wtd [ Mon Jun 27, 2005 3:15 pm ] | ||
Post subject: | |||
Presumably each score is connected to a name. Create a HighScoreRecord class. (Java 1.4.2)
Now you can just have a single list of those. ![]() |
Author: | Aziz [ Mon Jun 27, 2005 3:41 pm ] | ||
Post subject: | |||
Awesome, I'm going to try that later. And actually try to understand it, instead of just copy and paste it. But not right now. I'm going to go play some Xbox. Thanks a bunch. Oh and one more question. How do you get the java code tags? Instead of just:
Thanks ![]() |
Author: | wtd [ Mon Jun 27, 2005 3:50 pm ] | ||
Post subject: | |||
|