Note that there are some explanatory texts on larger screens.

plurals
  1. POInterface Misunderstanding
    text
    copied!<p>I'm trying to increase my productivity and extensibility with Interfaces. They are quite powerful, but I've hit a snag in either my understanding or implementation. </p> <p>Hypothetically, if I have a <em>User Interface</em> that I have no control over; but I'm writing a <em>Class Library</em> that will perform a series of logic. My original thought was something like this:</p> <pre><code>public interface ISiteForm { public string FirstName { get; set; } public string LastName { get; set; } // Also any other User Interface Form Fields. } </code></pre> <p>Which would be laid out like this, so it could be implemented and referenced by the <em>User Interface</em>.</p> <pre><code>public class SiteForm : ISiteForm { public SiteForm() { FormPass(); } public string FirstName { get { return firstName; } set { firstName = value; } } public string LastName { get { return lastName; } set { lastName = value; } } private string lastName, private string firstName, public void FormPass(string _lastName, string _firstName) { // Implementation to assign a value from User Interface into the interface. lastName = _lastName; firstName = _firstName; } } </code></pre> <p>My thought was when the <em>Class Library</em> was referenced, they would pass those parameters to the method when it was called. Then by nature when the class was created; it would assign those variables to the interface.</p> <p>So then if I had any other portion of the project that required those same variables; I could simply call the interface and adjust the setter value.</p> <p>My concerns are:</p> <ul> <li>Interfaces by nature don't expect logic</li> <li>They are usually Polymorphic, which would lose that specific implementation.</li> </ul> <p>Is that the wrong approach for passing parameters through an interface so those same variables can be used elsewhere? </p>
 

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