<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>{ Duane.Wingett } - Scope</title>
    <link>http://www.duanewingett.info/</link>
    <description>.Net Code Monkey</description>
    <language>en-gb</language>
    <copyright>Duane Wingett</copyright>
    <lastBuildDate>Thu, 02 Sep 2010 18:06:44 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>mail@duanewingett.info</managingEditor>
    <webMaster>mail@duanewingett.info</webMaster>
    <item>
      <trackback:ping>http://www.duanewingett.info/Trackback.aspx?guid=5967e8bc-786b-4dba-bb90-a68eb3c13017</trackback:ping>
      <pingback:server>http://www.duanewingett.info/pingback.aspx</pingback:server>
      <pingback:target>http://www.duanewingett.info/PermaLink,guid,5967e8bc-786b-4dba-bb90-a68eb3c13017.aspx</pingback:target>
      <dc:creator>Duane Wingett</dc:creator>
      <wfw:comment>http://www.duanewingett.info/CommentView,guid,5967e8bc-786b-4dba-bb90-a68eb3c13017.aspx</wfw:comment>
      <wfw:commentRss>http://www.duanewingett.info/SyndicationService.asmx/GetEntryCommentsRss?guid=5967e8bc-786b-4dba-bb90-a68eb3c13017</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <h3>Mixed Scope Properties in .Net
</h3>
        <p>
There may be a time when you want to have mixed scope for your "Getters" and "Setters"
in a property. For those of you who are not familiar with the syntax here it is
</p>
        <p>
VB:
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Public</span>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Property</span> MyProperty <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">as</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">String</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Get</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Return</span> _myField <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">End</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Get</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Private</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Set</span> _myField <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> Value <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">End</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Set</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">End</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Property</span></span>
        </pre>
        <p>
This example allows a public "Getter" and a private "Setter". 
</p>
        <p>
The same can be done in C#:
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> MyProperty
{ <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">get</span> { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">return</span> _myField;
} <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">private</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">set</span> {
_myField <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> value;
} }</span>
        </pre>
        <p>
Hope you find that useful.
</p>
        <p>
Regards,
</p>
        <p>
Dib.
</p>
        <img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=5967e8bc-786b-4dba-bb90-a68eb3c13017" />
      </body>
      <title>Mixed Scope Properties in .Net</title>
      <guid isPermaLink="false">http://www.duanewingett.info/PermaLink,guid,5967e8bc-786b-4dba-bb90-a68eb3c13017.aspx</guid>
      <link>http://www.duanewingett.info/2010/09/02/MixedScopePropertiesInNet.aspx</link>
      <pubDate>Thu, 02 Sep 2010 18:06:44 GMT</pubDate>
      <description>&lt;h3&gt;Mixed Scope Properties in .Net
&lt;/h3&gt;
&lt;p&gt;
There may be a time when you want to have mixed scope for your "Getters" and "Setters"
in a property. For those of you who are not familiar with the syntax here it is
&lt;/p&gt;
&lt;p&gt;
VB:
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Property&lt;/span&gt; MyProperty &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;as&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;String&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Get&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Return&lt;/span&gt; _myField &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;End&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Get&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Private&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Set&lt;/span&gt; _myField &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; Value &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;End&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Set&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;End&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Property&lt;/span&gt; &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
This example allows a public "Getter" and a private "Setter". 
&lt;/p&gt;
&lt;p&gt;
The same can be done in C#:
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; MyProperty
{ &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;get&lt;/span&gt; { &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/span&gt; _myField;
} &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;private&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;set&lt;/span&gt; {
_myField &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; value;
} }&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
Hope you find that useful.
&lt;/p&gt;
&lt;p&gt;
Regards,
&lt;/p&gt;
&lt;p&gt;
Dib.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=5967e8bc-786b-4dba-bb90-a68eb3c13017" /&gt;</description>
      <comments>http://www.duanewingett.info/CommentView,guid,5967e8bc-786b-4dba-bb90-a68eb3c13017.aspx</comments>
      <category>.Net</category>
      <category>Asp.Net</category>
      <category>C#</category>
      <category>Scope</category>
      <category>VB Script</category>
    </item>
    <item>
      <trackback:ping>http://www.duanewingett.info/Trackback.aspx?guid=e52ed85e-a815-451e-862d-710c6113e52a</trackback:ping>
      <pingback:server>http://www.duanewingett.info/pingback.aspx</pingback:server>
      <pingback:target>http://www.duanewingett.info/PermaLink,guid,e52ed85e-a815-451e-862d-710c6113e52a.aspx</pingback:target>
      <dc:creator>Duane Wingett</dc:creator>
      <wfw:comment>http://www.duanewingett.info/CommentView,guid,e52ed85e-a815-451e-862d-710c6113e52a.aspx</wfw:comment>
      <wfw:commentRss>http://www.duanewingett.info/SyndicationService.asmx/GetEntryCommentsRss?guid=e52ed85e-a815-451e-862d-710c6113e52a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I'm sure most of us endeaver to keep the tightest scope possible for the members of
classes we write. But I have a situation where I just can't seem to be able to keep
the scope of members of my inherited class as tight as I would like.
</p>
        <p>
What I am intending to create is a <strong>Job</strong> object that will inherit from
a <strong>BaseJob</strong> object that will implement the <strong>IJob</strong> interface.
While doing this I want to ensure the <strong>JobFactory</strong> member of the <strong>Job</strong> object
is kept private and the <strong>Id</strong> member is public. Both of these members
belong in the <strong>BaseJob</strong> object.
</p>
        <p>
So I'll start with new assembly that will contain three interfaces; <strong>IJob,
IIdentifyable</strong> and <strong>IJobFactory</strong>. 
</p>
        <pre>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">interface</span>
            <font color="#7fffd4">IJob</font> : <font color="#7fffd4">IIdentifyable</font> { <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;summary&gt;</span><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
Gets or sets a reference to the factory that created the IJob object.</span><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;/summary&gt;</span><font color="#7fffd4">IJobFactory</font> JobFactory { <font color="#0000ff">get</font>; <font color="#0000ff">set</font>;
} }</span>
        </pre>
        <pre>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
          </span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;summary&gt;</span>
                <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
Represents the signature for an object that is identifyable<br /></span>
              </span>
            </span>
          </span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;/summary&gt;</span> public</span>
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">interface</span>
              <font color="#7fffd4">IIdentifyable</font> { <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;summary&gt;</span><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
Gets or sets a reference to the identity of the IJob object.</span><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;/summary&gt;</span><font color="#0000ff">int</font> Id { <font color="#0000ff">get</font>; <font color="#0000ff">set</font>;
} }</span>
          </span>
        </pre>
        <pre>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            </span>
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;summary&gt;</span>
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
Represents the signature required for a job factory.</span>
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;/summary&gt;</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">interface</span>
            <font color="#7fffd4">IJobFactory</font> { <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;summary&gt;</span><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
Creates an object that implements the IJob interface.</span><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;/summary&gt;</span><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;returns&gt;Returns an object that implements the IJob interface&lt;/returns&gt;</span><font color="#7fffd4">IJob</font> Create(); <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;summary&gt;</span><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
Saves the current job</span><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;/summary&gt;</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</span> Save(<font color="#7fffd4">IJob</font> job);
}</span>
        </pre>
        <p>
          <strong>IJob</strong> has a member which will be used to hold a reference to an
object (that implements the <strong>IJobFactory</strong> inteface) that created it.
It will also have a Id member implemented through the <strong>IIdentifyable</strong> interface. <strong>IJobFactory</strong> has
a method for returning a newly created object that implements the <strong>IJob</strong> interface
and a method to save an object that implements the <strong>IJob</strong> interface.
Both interfaces must be <font color="#0000ff">public</font> as they need to be seen from
outside the assembly. As far as I am aware you canot declare the scope of the methods
in an interface so each will be of the same scope as the interface.
</p>
        <p>
I now need to another new assembly which will contain a base class (<strong>BaseJob</strong>)
for my <strong>Job</strong> object to inherit from. I create a reference to the interfaces
assembly, and allow the <strong>BaseJob</strong> class will implement the <strong>IJob</strong> interface
from it.
</p>
        <pre>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;summary&gt;</span>
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
The base class that all Job objects should inherit from.</span>
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;/summary&gt;</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">abstract</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> BaseJob
: IJob { <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">private</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> _id; <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">private</span><font color="#7fffd4">IJobFactory</font> _jobFactory; <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">#region</span> IIdentifyable
Members <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;summary&gt;</span><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
Represents the identity of an Job</span><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;/summary&gt;</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> Id
{ <font color="#0000ff">get</font> { <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span> _id
; } <font color="#0000ff">set</font> { _id <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> value;
} } <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">#endregion</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">#region</span> IJob
Members <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;summary&gt;</span><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
Gets or sets a reference to the factory that created the IJob object.</span><span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;/summary&gt;</span><font color="#0000ff">public</font><font color="#7fffd4">IJobFactory</font> JobFactory
{ <font color="#0000ff">get</font> { <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span> _jobFactory;
} <font color="#0000ff">set</font> { _jobFactory <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> value;
} } <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">#endregion</span> }</span>
        </pre>
        <p>
Now, I would like to set the scope of the <strong>BaseJob</strong>'s <strong>Id</strong> and <strong>Jobfactory</strong> members
as <font color="#0000ff">protected</font>, do they can only be seen by objects that
inherit from the <strong>BaseJob</strong> object. However if I try and make the
scope any tighter then VS advises me of an error when I try to build.
</p>
        <p>
          <font face="Courier New" color="#ff0000">Error 1 'BaseJob' does not implement
interface member 'IJob.JobFactory'. 'BaseJob.JobFactory' is either static, not public,
or has the wrong return type.</font>
        </p>
        <p>
So as far as I can see it has to stay <font color="#0000ff">public</font>. Any way
on to my <strong>Job</strong> object now. In a third assembly, which has a reference
to both the base class assembly and the interfaces assembly,  I create the <strong>Job</strong> class.
</p>
        <pre>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> Job
: BaseJob { <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span> Job(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span> id, <font color="#7fffd4">IJobFactory</font> jobFactory)
: <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">base</span>()
{ <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">base</span>.Id <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> id; <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">base</span>.JobFactory <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> jobFactory;
} }</span>
        </pre>
        <p>
The <strong>Job</strong> class has a contructor which allows me to pass in the identity
and the JobFactory which is used to create it ( I hope to write an post / question
on dependency injection next!). My problem is I don't intend the <strong>JobFactory</strong> property
of the <strong>Job</strong> object to be visiable outside the class code, so ideally
I would like to scope it as <font color="#0000ff">private</font>. However it is an
inherited member that already has a scope of <font color="#0000ff">public</font>.
I can quite clearly see the member like so...
</p>
        <pre>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</span> TestClass
{ <font color="#7fffd4">Job</font> _job; <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span> TestClass()
{ _job <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span><font color="#7fffd4">Job</font>();
_job.JobFactory <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> ...;
} }</span>
        </pre>
        <p>
The only way I can see to hide the member is by overriding the <font color="#7fffd4">JobFactory</font> member
to the <font color="#7fffd4">Job</font> object with the <font color="#0000ff">new</font> modifier
like so.
</p>
        <pre>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">private</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</span> IJobFactory
JobFactory { <font color="#0000ff">get</font> { <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">base</span>.JobFactory;
} }</span>
        </pre>
        <p>
Is this really the best way to go about this, or am I doing something fundementally
wrong? Your comments appreciated!
</p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=e52ed85e-a815-451e-862d-710c6113e52a" />
      </body>
      <title>Interfaces, Inheritance and Scope - Am I being some kind of fool? It is April, afterall.</title>
      <guid isPermaLink="false">http://www.duanewingett.info/PermaLink,guid,e52ed85e-a815-451e-862d-710c6113e52a.aspx</guid>
      <link>http://www.duanewingett.info/2008/04/01/InterfacesInheritanceAndScopeAmIBeingSomeKindOfFoolItIsAprilAfterall.aspx</link>
      <pubDate>Tue, 01 Apr 2008 20:35:00 GMT</pubDate>
      <description>&lt;p&gt;
I'm sure most of us endeaver to keep the tightest scope possible for the members of
classes we write. But I have a situation where I just can't seem to be able to keep
the scope of members of my inherited class as tight as I would like.
&lt;/p&gt;
&lt;p&gt;
What I am intending to create is a &lt;strong&gt;Job&lt;/strong&gt; object that will inherit from
a &lt;strong&gt;BaseJob&lt;/strong&gt; object that will implement the &lt;strong&gt;IJob&lt;/strong&gt; interface.
While doing this I want to ensure the &lt;strong&gt;JobFactory&lt;/strong&gt; member of the &lt;strong&gt;Job&lt;/strong&gt; object
is kept private and the &lt;strong&gt;Id&lt;/strong&gt; member is public. Both of these members
belong in the &lt;strong&gt;BaseJob&lt;/strong&gt; object.
&lt;/p&gt;
&lt;p&gt;
So I'll start with new assembly that will contain&amp;nbsp;three interfaces; &lt;strong&gt;IJob,
IIdentifyable&lt;/strong&gt;&amp;nbsp;and &lt;strong&gt;IJobFactory&lt;/strong&gt;. 
&lt;/p&gt;
&lt;pre&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;interface&lt;/span&gt; &lt;font color=#7fffd4&gt;IJob&lt;/font&gt; : &lt;font color=#7fffd4&gt;IIdentifyable&lt;/font&gt; { &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
Gets or sets a reference to the factory that created the IJob object.&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;font color=#7fffd4&gt;IJobFactory&lt;/font&gt; JobFactory { &lt;font color=#0000ff&gt;get&lt;/font&gt;; &lt;font color=#0000ff&gt;set&lt;/font&gt;;
} }&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
Represents the signature for an object that is identifyable&lt;br&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;interface&lt;/span&gt; &lt;font color=#7fffd4&gt;IIdentifyable&lt;/font&gt; { &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
Gets or sets a reference to the identity of the IJob object.&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;font color=#0000ff&gt;int&lt;/font&gt; Id { &lt;font color=#0000ff&gt;get&lt;/font&gt;; &lt;font color=#0000ff&gt;set&lt;/font&gt;;
} }&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
Represents the signature required for a job factory.&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;interface&lt;/span&gt; &lt;font color=#7fffd4&gt;IJobFactory&lt;/font&gt; { &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
Creates an object that implements the IJob interface.&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;returns&amp;gt;Returns an object that implements the IJob interface&amp;lt;/returns&amp;gt;&lt;/span&gt; &lt;font color=#7fffd4&gt;IJob&lt;/font&gt; Create(); &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
Saves the current job&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/span&gt; Save(&lt;font color=#7fffd4&gt;IJob&lt;/font&gt; job);
}&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;strong&gt;IJob&lt;/strong&gt; has a member which will be used to hold a reference to&amp;nbsp;an
object (that implements the &lt;strong&gt;IJobFactory&lt;/strong&gt; inteface) that created&amp;nbsp;it.
It will also have a Id member implemented through the &lt;strong&gt;IIdentifyable&lt;/strong&gt; interface.&amp;nbsp;&lt;strong&gt;IJobFactory&lt;/strong&gt; has
a method for returning a newly created object that implements the&amp;nbsp;&lt;strong&gt;IJob&lt;/strong&gt; interface
and a method to save an object that implements the &lt;strong&gt;IJob&lt;/strong&gt; interface.
Both interfaces must be &lt;font color=#0000ff&gt;public&lt;/font&gt; as they need to be seen&amp;nbsp;from
outside the assembly. As far as I am aware you canot declare the scope of the methods
in an interface so each will be of the same scope as the interface.
&lt;/p&gt;
&lt;p&gt;
I now need to another new assembly which will contain a base class (&lt;strong&gt;BaseJob&lt;/strong&gt;)
for my &lt;strong&gt;Job&lt;/strong&gt; object to inherit from. I create a reference to the interfaces
assembly, and allow the &lt;strong&gt;BaseJob&lt;/strong&gt; class will implement the &lt;strong&gt;IJob&lt;/strong&gt; interface
from it.
&lt;/p&gt;
&lt;pre&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
The base class that all Job objects should inherit from.&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;abstract&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; BaseJob
: IJob { &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;private&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/span&gt; _id; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;private&lt;/span&gt; &lt;font color=#7fffd4&gt;IJobFactory&lt;/font&gt; _jobFactory; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;#region&lt;/span&gt; IIdentifyable
Members &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
Represents the identity of an Job&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/span&gt; Id
{ &lt;font color=#0000ff&gt;get&lt;/font&gt; { &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;return&lt;/span&gt; _id
; } &lt;font color=#0000ff&gt;set&lt;/font&gt; { _id &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; value;
} } &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;#endregion&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;#region&lt;/span&gt; IJob
Members &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
Gets or sets a reference to the factory that created the IJob object.&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;font color=#0000ff&gt;public&lt;/font&gt; &lt;font color=#7fffd4&gt;IJobFactory&lt;/font&gt; JobFactory
{ &lt;font color=#0000ff&gt;get&lt;/font&gt; { &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;return&lt;/span&gt; _jobFactory;
} &lt;font color=#0000ff&gt;set&lt;/font&gt; { _jobFactory &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; value;
} } &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;#endregion&lt;/span&gt; }&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
Now, I would like to set the scope of the &lt;strong&gt;BaseJob&lt;/strong&gt;'s&amp;nbsp;&lt;strong&gt;Id&lt;/strong&gt; and &lt;strong&gt;Jobfactory&lt;/strong&gt; members
as &lt;font color=#0000ff&gt;protected&lt;/font&gt;, do they can only be seen by objects that
inherit from the &lt;strong&gt;BaseJob&lt;/strong&gt; object. However if I try and&amp;nbsp;make&amp;nbsp;the
scope any tighter then VS advises me of an error when I try to build.
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New" color=#ff0000&gt;Error&amp;nbsp;1&amp;nbsp;'BaseJob' does not implement
interface member 'IJob.JobFactory'. 'BaseJob.JobFactory' is either static, not public,
or has the wrong return type.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
So as far as I can see it has to stay &lt;font color=#0000ff&gt;public&lt;/font&gt;. Any way on
to my &lt;strong&gt;Job&lt;/strong&gt; object now. In a third assembly, which has a reference
to both the base class assembly and the interfaces assembly,&amp;nbsp;&amp;nbsp;I create the &lt;strong&gt;Job&lt;/strong&gt; class.
&lt;/p&gt;
&lt;pre&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; Job
: BaseJob { &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; Job(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/span&gt; id, &lt;font color=#7fffd4&gt;IJobFactory&lt;/font&gt; jobFactory)
: &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;base&lt;/span&gt;()
{ &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;base&lt;/span&gt;.Id &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; id; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;base&lt;/span&gt;.JobFactory &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; jobFactory;
} }&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
The &lt;strong&gt;Job&lt;/strong&gt; class has a contructor which allows me to pass in the identity
and the JobFactory which is used to create it ( I hope to write an post / question
on dependency injection next!). My problem is I don't intend the &lt;strong&gt;JobFactory&lt;/strong&gt; property
of the &lt;strong&gt;Job&lt;/strong&gt; object to be visiable outside the class code, so ideally
I would like to scope it as &lt;font color=#0000ff&gt;private&lt;/font&gt;. However it is an inherited
member that already has a scope of &lt;font color=#0000ff&gt;public&lt;/font&gt;. I can quite
clearly see the member like so...
&lt;/p&gt;
&lt;pre&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; TestClass
{ &lt;font color=#7fffd4&gt;Job&lt;/font&gt; _job; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; TestClass()
{ _job &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; &lt;font color=#7fffd4&gt;Job&lt;/font&gt;();
_job.JobFactory &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; ...;
} }&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
The only way I can see to hide the member is by&amp;nbsp;overriding the&amp;nbsp;&lt;font color=#7fffd4&gt;JobFactory&lt;/font&gt; member
to the &lt;font color=#7fffd4&gt;Job&lt;/font&gt; object with the &lt;font color=#0000ff&gt;new&lt;/font&gt; modifier
like so.
&lt;/p&gt;
&lt;pre&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;private&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; IJobFactory
JobFactory { &lt;font color=#0000ff&gt;get&lt;/font&gt; { &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;return&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;base&lt;/span&gt;.JobFactory;
} }&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
Is this really the best way to go about this, or am I doing something fundementally
wrong? Your comments appreciated!
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=e52ed85e-a815-451e-862d-710c6113e52a" /&gt;</description>
      <comments>http://www.duanewingett.info/CommentView,guid,e52ed85e-a815-451e-862d-710c6113e52a.aspx</comments>
      <category>.Net</category>
      <category>C#</category>
      <category>Inheritance</category>
      <category>Interfaces</category>
      <category>Scope</category>
    </item>
  </channel>
</rss>