Suggested oop design

i need ur suggestions building oop model for the following case:
- a parent class that represent a WebPage object. this class represent the common shared members between any web page.

- child classes that represent any web page (contact us, about us, ...), where the parent will be the common WebPage object above.

- a startup class that will start the application (say like the main method) and initialize the parent WebPage object.

the startup class will receive arguments, one of the argument will decide which web page(child) to open, other arguments will be used to assign some members in the parent class, to be more clear take a look at the following:

[code]
class WebPage //the parent
{
some members...
}

class AboutUs:WebPage //a web page child
{
some members...
}

class ContactUs:WebPage //a web page child
{
some members...
}

class startup
{
main(argWebPageToOpen, argParentMember1,argSomeParentMember2)
{
WebPage webPage = new WebPage();
webPage.Member1 = argSomeParentMember1
webPage.Member2 = argSomeParentMember2

if(argWebPageToOpen == AboutUs)
new AboutUs()
else if(argWebPageToOpen == ContactUs)
new ContactUs()
}

}
[/code]

now the problem in the above code is that the children objects need to be inherited from a parent which has been initialized using outside arguments, where in the above example they didnt, so how to accomplish such design where the first solution flashed in my mind was to create initializer constructor for the child class that accept the arguments and then send it to its parent initializer constructor but i didnt like this solution, so any other ideas?? and plz if u need more clearer description ask me for it cuz am not sure if i have explain my problem well.

Comments

  • ya I'm really not sure I'm understanding what you are asking - but here is what I think you are saying

    You have a class that has some required parameters in the constructor that you want to inherit from, but you don't want the child classes to have any parameters in their constructors... is this correct?

    If that is the case then you have to somehow set the values in the constructor for the base class - but if you have a solid set of default values you can do something like this:

    [code]
    public class WantsArgs
    {
    public int Property { get; set; }
    public WantsArgs(int arg)
    {
    Property = arg;
    }
    }

    public class NoArgs : WantsArgs
    {
    public NoArgs() : base(1)
    {

    }
    }

    class Program
    {
    static void Main(string[] args)
    {
    var m = new NoArgs();

    }
    }


    [/code]

    the "public NoArgs() : base(1)" will construct the base class with a default value of 1 - thus meeting the argument requirements of the base class constructor without having to have any arguments in the child class constructor.

    ><//~Psightoplasm`~
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion