Initialize Variable vs override in public class
public class IShoes {
public string name {get; protected set;}
public virtual int NUM { get; protected set; }
}
public class WornShoe : IShoes {
public WornShoe() {
name = "Worn Shoes";
}
public override NUM {get{return 10;}}
}
i am unsure which one to use, i can either declare everything in public WornShore() (ex: name) or to override and virtual everything (ex: NUM). Can anyone give me advice on the advantages/disadvantages of either way? or suggest a different way.
i am sorry if i use the wrong terms
Answer by Zodiarc · Nov 04, 2016 at 09:33 AM
First of all IShoes seems to be an interface. If yes, change it form public class to public interface.
I doubt you need accessor overriding. Simply setting the variable as you do in the WornShoe constructor is enough. It would overcomplicate the code unnecessarily.
public interface IShoes {
}
public abstract class AbstractShoe : IShoes {
public string name {get; protected set;}
public int NUM { get; protected set; }
}
public class WornShoe : AbstractShoes {
public WornShoe() {
name = "Worn Shoes";
NUM = 10;
}
}
Your answer
Follow this Question
Related Questions
Sound in Unity is not working! WHY? 0 Answers
Is this true? 1 Answer
C# Newbie Programming Questions 0 Answers
Hiding part of mesh 0 Answers
Saving and Loading from scene to scene.. 0 Answers