Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Problem within classes to access values

$
0
0

I am developing application to monitor some server over the network. I prepared simply class Server which give me IP and Protocol which give me Name of protocol then in class Heartbeat supervisor in some method I want to take those two values and do e.g ping. There is also base class Cocpit which gives to Server and Protocol Properties Id and name. My problem is I cant access the Server and Protocol from Heartbeat and its logic because since I got protected I cant access. My question is how to rebuilt that app (but with OOP conversion) so y code could work as I want please check actual code:

public abstract class Cocpit: ICheck{    protected string id;    protected virtual string Id    {        get { return id; }        set { id = value; }    }    protected string name;    protected virtual string Name    {        get { return name; }        set { name = value; }    }

in Server I did: (no need to implement own condition just use values

publicclassServer:Cocpit{publicServer(string name,string ip):base(name){base.Id= ip;//could be without base wordbase.Name= name;}

inside Protocol I implemented new conditions for Id

publicclassProtocol:Cocpit{/// This constructor will call Cocpit.Cocpit()publicProtocol(string name):base(name){base.Name="dd";}protectedoverridestringId{

        get {returnnull;}set{//dont need to use base wordif(base.id != value)return;//only example condition//DoSomethingOnWrite(id, value);base.id = value;}//set Id}

and after all when want to use inside Heartbeate I cant access protocol.Name inside constructor - how to access that? I know that because I need to go through heartbeat and not Server object but don't know how to handle that within my whole code conception.

this._protocolName = protocol.Name;publicclassHeartbeatSupervisor:ICheck{privatestring _serverIp;privatestring _protocolName;protectedstringServerIp{
     get {return _serverIp;}set{ _serverIp = value;}}protectedstringProtocolName{
     get {return _protocolName;}set{ _protocolName = value;}}publicHeartbeatSupervisor(Server server,Protocol protocol){this._serverIp = server.Ip;this._protocolName = protocol.Name;}}

after all inside Program class I want to raise Heartbeatsupervisor to pas it Server and protocol and raise some method to do calulcation.


Viewing all articles
Browse latest Browse all 31927

Trending Articles