Thread: How to organize classes and interfaces in files

  1. #1
    Registered User
    Join Date
    Jul 2017
    Posts
    8

    How to organize classes and interfaces in files

    In a game project there is a CS file with character interface and derived classes, all about different characters and their properties. I assume there should be other classes for other game stuff.
    1) Is it correct that I create separate file for another game object type, for example Weapon?
    2) Is it correct to also include related interfaces in this file?
    3) What is the role of interfaces here rather than just using a common base class?
    4) Can you name a short example why I need interfaces in games?

  2. #2
    Registered User
    Join Date
    Jul 2017
    Posts
    8
    Looks like I didn't know enough about interfaces here.

    1) Correct
    2) Correct
    3) Define the functionality that the inheriting classes should implement
    4) The same as interfaces in other applications
    Last edited by UltimateGames; 08-14-2017 at 04:26 AM.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    you do not want to combine interfaces and implementation classes in the same file
    user of your class only interested in the interface - so this is what he should be able to see
    your class could resize in the different assembly that could be delivered as dll without opening the code of the class
    In this case just by adding dll with class implementing new type of character - you can extend the functionality of the application without rewriting the application code since it was only interested in the interface
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Classes and .h files
    By jocdrew21 in forum C++ Programming
    Replies: 12
    Last Post: 09-10-2013, 03:04 AM
  2. The correct way to organize source code into classes
    By MathFan in forum C++ Programming
    Replies: 4
    Last Post: 12-22-2010, 01:25 PM
  3. Replies: 2
    Last Post: 08-11-2009, 06:45 AM
  4. Header files and classes
    By disruptivetech in forum C++ Programming
    Replies: 5
    Last Post: 04-21-2008, 09:02 AM
  5. Most readable way to organize variables and files?
    By SourceCode in forum C Programming
    Replies: 4
    Last Post: 04-19-2003, 02:19 AM

Tags for this Thread