Jump to content
  • Advertisement

de_mattT

Member
  • Content count

    27
  • Joined

  • Last visited

Community Reputation

308 Neutral

About de_mattT

  • Rank
    Member
  1. Agreed.   So while you'll probably still need some way of checking that the colleciton contains the key->value mapping, you only need to do it once when the key is received from the user.   Speaking in terms of a generic collection object, a return value of NULL from your function value* getThing(const key&); ) could mean that the key is mapped onto NULL or that the key is not in the map. You've already mentioned that keys will not be mapped onto null values, so in this instance a return value of NULL can only mean that the key is not in the collection. However will that always be the case? Are you intending to re-use the collection? Also someone updating the code in the future may not immediatly appreciate that a return value of NULL can only be generated when the key isn't mapped. Therefore, while NULL checks would work, I think adding explicit 'exists' checks could make your code easier to read and make the collection class more re-usable.   Both of your suggestions look like fine choices.   Another option you might want to consider, (although I'd still go with the 'bool exists(const key&)' suggestion) is to have your collection return a default object when the key isn't stored. The object would be an instance of a default class, extending the class of the values stored in the collection, but stubbing out all procedures so that they do nothing and all functions so that they return neutral values. Then the rest of your code can process the default object as if a key-value map was found, removing the need for any 'exists' or 'is NULL' checks. (The NULL Object pattern, from Robert Martin's book 'Agile Softwaree Development: Principles, Patterns and Practices')
  2. Just to add to dr01d3k4's explanation, static members are class members and therefore accessed through the class, non-static members are object (instance) members and are accessed via an object / instance.
  3. Or an alternative would be to create the instances of Appointment when you create DayPlanner, e.g. public class Planner { Appointment[] DayPlanner = new Appointment[] {new Appointment(), new Appointment(), new Appointment()}; } DayPlanner is an array with 3 elements.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!