   Good Practices with Interfaces in C#
  Can interfaces have member variables? If not, it is acceptable to have class member variables that are only to be used for an implemented interface?   
Quote:Original post by KalthornCan interfaces have member variables? No, interface can have neither member variables nor properties. Quote:If not, it is acceptable to have class member variables that are only to be used for an implemented interface?I'm not sure I understand what you're trying to say, but abstract classes might be a good starting point.   ;  Interfaces can have properties, albeit abstracted:public interface Foo{    string Bar{ get; set; }};  Uhm, yes. I guess I wasn't clear at all...   ;  Sorry about the lack of details before, I was being rushed.I'm setting up a base object that most everything else will inherit.  I want my objects to handle their own functions such as rendering, but not every object will need to be rendered.  After thinking about it a bit, I guess my best option for a RenderObject would be inheriting from the base class, implementing a rendering interface and adding variables to hold my rendering data.  Is that the most accepted way to go?As a sort of off-topic question, should objects render themselves in terms of OOP?  I've read differing views and while I tend to agree that objects should not render themselves (they should hold and operate on data related to the game, not how the game is seen), I can't think of a simple way to implement this without identical data in multiple classes (the object holding its location and status and the rendering class needing the same data for animation, etc) or a blurring of class lines through shared data.   ;  Personally, I'd prefer an empty Render() implementation for the few derivations that don't need one than checking if the interface exists or including it and then duplicating the member vars to make it work.Generally, a view of an object will either contain a reference to that object (which in turn knows nothing of the view), or the view is controlled by something which knows of both the view and the model/object (both of which in turn know nothing about the controller).   ;Quote:Original post by KalthornSorry about the lack of details before, I was being rushed.I'm setting up a base object that most everything else will inherit.  I want my objects to handle their own functions such as rendering, but not every object will need to be rendered.  After thinking about it a bit, I guess my best option for a RenderObject would be inheriting from the base class, implementing a rendering interface and adding variables to hold my rendering data.  Is that the most accepted way to go?This is how I'd do it:Create an interface IRenderable, that all renderable objects should inherit from. IRenderable contains a virtual function called "GetRenderInformation()" that returns some sort of struct or something; this function is used by the renderer. All renderable objects should implement this function by returning necessary information required by the renderer.;  There are two design patterns that may aid you in solving this problem. The first one is the model/view(/controller)-pattern, which has already been mentioned, so I'm just gonna link to wiki-pedia.The other one is the visitor pattern; it helps you move code out of a class that would normally have to be in a method because it is different for every class in the class hirachy.Basically with the visitor pattern (in case you're not familiar with it already), you need to make your classes visitable - that is, add a void accept(Visitor visitor) method to all of them that simply calls visitor.visit(this)since that method knows the exact class of this, it's going to call the right method in your visitor, which needs a method corresponding to each of your visitable classes, ie.class Visitor {    void visit(Rocket object);    void visit(Backpack object);    // ... etc.}The downside is that you still need to make enough internal information public to be able to draw it from outside the actual class. Hope it helps a bit.   ;  Thanks to everyone who replied, you helped me quite a bit :)   