Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to *easily* expose methods of underlying objects?
    primarykey
    data
    text
    <p>Let's say I have some classes defined as follows:</p> <pre><code>class Security { Boolean AuthenticateUser(String username, String password); Boolean AddUser(String username, String password); // many more methods } class NetworkedDevice { void Stop(); void Start(); // many more methods } </code></pre> <p>Then I have another class that contains instances of the above classes. How can I avoid code like the following? I want all the methods of class1 and class2 exposed via this class.</p> <pre><code>class MyWindowsService { Security _security = new Security(); NetworkDevice _netDevice = new NetworkDevice(); Boolean AuthenticateUser(String username, String password) { return _security.AuthenticateUser(username, password); } // all the rest of "Security" methods implemented here void StopNetworkDevice() { _netDevice.Stop(); } void StartNetorkDevice() { _netDevice.Start(); } // all the rest of "NetDevice" methods implemented here } </code></pre> <p><em>Edit</em> I've updated the code to be more <em>real</em> to what I am doing. I am hosting a WCF service within a windows service. The windows service does several things including user authentication and communication to networked devices to name a few. The implementation of my WCF interface calls methods of the "MyWindowsService" class. Exposing the underlying objects as properties is the answer I was looking for. The above class then looks something like:</p> <pre><code>class MyWindowsService { SecurityClass _security = new SecurityClass(); NetworkDevice _netDevice = new NetworkDevice(); Public NetworkDevice NetDevice { get { return _netDevice; } } Public SecurityClass Security { get { return _security; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload