I have the following classes:-
Common
: contains common methods
Tab
: represents a single tab in a browser
Window
: represents the browser window
Class Common
{
public goURL()
{
//method definition
}
}
Class Tab
{
int tab_id;
string tab_name;
Common common;
public Tab(tab_id, tab_name)
{
this.tab_id = tab_id;
this.tab_name = tab_name;
common = new Common();
}
public void createNewTab()
{
//method definition
this.common.goURL();
}
}
Class Window
{
public void startWindow()
{
//how do I access goURL() here using current instance of Tab?
}
public void newTabButton_Click(object sender, EventArgs e)
{
Tab T0 = new Tab(0, "Tab Zero");
T0.createNewTab();
}
}
How do I access the goURL()
method using the common
field inside an instance of Tab
class?
One option is to make the method static and access it without creating an object.
EDIT:
This was bad Object-Oriented design from my end. I ended up following the programming principles of High Cohesion and Loose Coupling to re-design my classes and come up with a better design. Thanks to everyone for the advice!