On Wednesday, 8 November 2017 at 17:46:42 UTC, Adam D. Ruppe wrote:
On Wednesday, 8 November 2017 at 17:38:27 UTC, Timoses wrote:
Are there better options/ways of achieving this?

What are you actually trying to achieve? What are you using these variables for?

Well, I have the following outline:

class File
{
    Section[] sections;
}
abstract class Section
{
    enum Part { Header, Content, Footer};
    SectionEntry[Part] entries;
}
class SectionEntry
{
    bool isComment;
    string[] lines;
}

And then I'd like to have somthing like predefined sections, e.g.:

class SectionTypeA : Section
{
.... // provide "static" information that is
     // always the same for this type of seciton
  // however, the Content part may vary
}


Are there more elegant ways of achieving this?


My first thought is you should abandon the variable approach and just use an abstract function that returns the value for each child via overriding. It won't be static, but it also won't take any per-instance memory.

Sounds like a good approach. I'll try this out for sure.

Reply via email to