CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2006
    Location
    Eastern, NC, USA
    Posts
    907

    Response to private question from radnire

    Quote Originally Posted by radnire
    Hey there, I have seen you posting a lot around the forums and was wandering if you could offer me a little advice.
    I have a simple problem and no problem coding it, just trying to work out how best to design the class structure.
    Basic system :
    There is a building, which has 1 or more floors.
    A floor has a name and one or more rooms.
    A room has a name and 1 - 5 guards.
    A guard has a name and may move between rooms and floors but can only bei n 1 room at a time.
    I am trying to come up with a class diagram for this and am having issues with the idea of interfaces/abstract classes.
    From that description I get the following information about the classes :
    Guard
    Variables : name, location
    Methods : GetName, SetName, CreateNew, GetLocation, SetLocation, Move
    Room
    Variables : name, location, contents
    Methods :GetName, SetName, CreateNew, GetContents, GetLocation, SetLocation, UpdateContents
    Floor
    Variables : name, contents
    Methods :GetName, SetName, CreateNew, GetContents, GetLocation, SetLocation, UpdateContents
    Building
    Variables : contents
    Methods :GetContents, UpdateContents
    From this I now have an issue with the interface/abstract class issue.
    I can envision an Abstract Class with data (name) and methods (GetName, SetName, CreateNew) which has subclasses Floor/Room/Guard
    I can then see 2 interfaces :
    hasLocation : GetLocation, SetLocation
    Implemented by Guard/Room
    Container : GetContents, UpdateContents
    Implemented by Room/Floor/Building
    This is all good and fine but im worried about the shared variables (loc, contents) which are not represented (would have to be defined in each relevant class) and surely with the use of interfaces there will be a LOT of repeat identical code between classes (which I always thought was a bad idea)
    I would really appreciate hearing your insight on the problem, this problem is going to give me much better understanding of interfaces/abstract classes.
    Thankyou in advance.
    To radnire: Many consider it inappropriate to ask questions such as these as a private message rather than in the forum, and I am among them. The reasons are several-fold and include:
    • The problem and solution aren't shared by all which is the main reason for existance of these forums (in my mind)
    • There's the chance (likely I think in this case) that you have asked the same question to multiple people causing many of us to spin our wheels by re-answer questions that have already been answered. We have lives to live too you know.
    • There's a chance (quite likely in this case) that this is a homework problem, and that you don't want the teacher to know that you've been asking for solutions to this problem.


    So for these and many more reasons, please ask all questions in the forum, not in private.

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Response to private question from radnire

    I got exactly the same message, and gave the same response. Looks like this guy is trying it on.

    The highest reward for a person's toil is not what they get for it, but what they become by it...
    J. Ruskin
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Response to private question from radnire

    petes and dlorde :
    If you feel someone is "bothering" you too frequently via PMs, feel free to contact a mod, and we will gladly help out

  4. #4
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Response to private question from radnire

    Quote Originally Posted by HanneSThEGreaT
    If you feel someone is "bothering" you too frequently via PMs, feel free to contact a mod, and we will gladly help out
    Understood. I think a single PM deserves the benefit of the doubt - but it helps to know if the same PM has gone to several people - that smells bad...

    Experience is a poor teacher: it gives its tests before it teaches its lessons...
    Anon.
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  5. #5
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Response to private question from radnire

    Well I didn't get PM'd which means either:

    He/she has read some of my posts and thought I wouldn't offer any help.
    or
    He/she has read some of my posts and thought I couldn't offer any help.

    I'm not sure whether I should be or

  6. #6
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Response to private question from radnire

    Quote Originally Posted by keang
    I'm not sure whether I should be or
    When in doubt, go with

    The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents...
    N. Borenstein
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured