Is it better to have a public readonly object, identical local readonly objects per class, or to directly reference a library object?
<p>I'm building a game using C# in XNA and I'm not sure which of these four ways is best to refer to the "Viewport" for reading access only:</p>

<ol>
<li><p>Have a public static variable that every class can access by calling Game.Viewport (Game is the main class:</p>

<p>public static readonly Viewport Viewport = GraphicsDevice.Viewport;</p></li>
</ol>

<p>in use:</p>

<pre><code>rectangle = new Rectangle (Game.Viewport/2, ...
</code></pre>

<ol>
<li><p>Have a local variable that refers to the Viewport for each class that needs the viewport:</p>

<p>private readonly Viewport viewport = GraphicsDevice.Viewport;</p></li>
</ol>

<p>in use:</p>

<pre><code>rectangle = new Rectangle (viewport/2, ...
</code></pre>

<ol>
<li><p>Use a local variable passed down into the constructor of each class that needs the viewport (this would be the only one that didn't require imported Microsoft.Xna.Framework.Graphics):</p>

<p>private readonly Viewport viewport;</p></li>
</ol>

<p>then in the constructor:</p>

<pre><code>viewport = pViewport;
</code></pre>

<p>in use:</p>

<pre><code>rectangle = new Rectangle (viewport/2, ...
</code></pre>

<ol>
<li><p>Directly reference the viewport from the class library everywhere where it's needed (in use):</p>

<p>rectangle = new Rectangle (GraphicsDevice.Viewport.Width/2, ...</p></li>
</ol>

<p>I wondering which one is best in terms of speed and which one is best in terms of readability. Personally, I feel like the fourth method would be easiest and fastest so I don't need to create any references to the Viewport and it's clear that I'm referring to something that is global. It seems like it's taking out the "middleman", but then you have to import the XNA graphics library to every class that uses the Viewport.</p>

<p>What do you guys think?</p>
