CST 338 - Week 3

Objects and Classes

In a previous data structures class, we needed to use a 4-dimensional array in an assignment that would find the shortest path between two stops in an airport schedule. The array kept track of routes between two airports and how many stops between them it would take. There was also a reference variable to the entry in another array that had the full list of layovers between the two airports. [Departing, Arriving, Stops Between, [itinerary entry]]. I didn't do great at the assignment. It was all very new to me at the time and looping through anything larger than a one-dimensional array was pretty confusing.

Now I think arrays in Java are best used if the information in the array needs to be consistently looked at in order, which becomes more uncommon the more dimensions you have. Unless you are performing an action on many elements in the array, there are more efficient data structures to use.

Other than homework assignments, I've never used inheritance to its full potential. Inheritance allows you to create a "Subclass" of an object. To use our Deck assignment as an example, you could have a "Deck" superclass and make "dealerDeck" and "playerDeck" objects that inherit all or some properties of the Deck parent class. This would allow you to have a game where the dealer and players have different things happen to their decks. You could then make small adjustments to each child class that reflect the needs of the game you're making. Like, for every player, the dealer gains an additional deck to compensate. 

This week was ourfull introduction on how to use multiple objects. Our assignment was to build a deck of cards using 3 different classes. A Card, Hand, and Deck. Card objects were contained in a array that acted as the master Deck object, that all other Deck objects were copied from. The Hand objects held cards in an array before either taking a new one or playing/discarding the Card objects. 

Comments

Popular Posts