1 / 8

Practical Uses of Interfaces in C#

Practical Uses of Interfaces in C#. By Kevin S. Goff. Who is Kevin S. Goff?. Founder and Principal Consultant: Common Ground Solutions 18 years experience - NET/SQL Server/Crystal Reports/Visual FoxPro 2005 Microsoft .NET MVP for C#

braeden
Download Presentation

Practical Uses of Interfaces in C#

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Practical Uses of Interfaces in C# By Kevin S. Goff

  2. Who is Kevin S. Goff? • Founder and Principal Consultant: Common Ground Solutions • 18 years experience - NET/SQL Server/Crystal Reports/Visual FoxPro • 2005 Microsoft .NET MVP for C# • Author of “The Baker’s Dozen” series in CoDe Magazine(Productivity Tips for .NET, Crystal Reports, and T-SQL) • Speaker at 2005 DevTeach, MSDN CodeCamp, .NET User Groups • Common Ground Framework for .NET (free framework) • Awards/citations from the Dept. of Agriculture/large corporations • www.commongroundsolutions.net / kgoff@commongroundsolutions.net • My Blog: http://www.TheBakersDozen.net Uses of Interfaces - Kevin S. Goff

  3. Definition of an interface • Interface is a contract that guarantees how a class will behave, and what properties and methods the class will contain.  • When you create an instance of a class that implements the interface, you can be assured that the class will contain  every PEM that the interface defined.  • Think of the interface as the bullet point list of what will be in the class. Uses of Interfaces - Kevin S. Goff

  4. Definition of an interface • OK…SO WHAT??? • What does that gain me??? • A popular INETA speaker has told people that they don't need to know about interfaces… Uses of Interfaces - Kevin S. Goff

  5. Three examples of interfaces • Distributed computing (remoting) • Generic Data Binding • Reusable data maintenance forms • All examples use the Common Ground Framework for .NET (my free framework) Uses of Interfaces - Kevin S. Goff

  6. Distributed computing (remoting) • Example: Login Authentication (must validate user ID/PW, via back-end objects) • IUserObject (one method, parms, and result) • Server side: • Methods that will be called via remoting must inherit from System.MarshalByRefObject • public class UserObject : CGS.Business.cgsBaseBusinessObject, Masonry.Interfaces.IUserObject • public class cgsBaseBusinessObject : System.MarshalByRefObject • Must register the object to be called via remoting through the registered TCP Channel TcpServerChannel Tcps = new TcpServerChannel(nTCPPort); ChannelServices.RegisterChannel(Tcps); RemotingConfiguration.RegisterWellKnownServiceType (typeof(Masonry.Server.BusinessObjects.UserObject), "UserObject" , WellKnownObjectMode.Singleton); • Client side (we don’t have the code, but we have interface and TCP port # • Create instance of interface object IUserObject oUserObject; ClientRemoteAccess oRemoteAccess = new ClientRemoteAccess(); oRemoteAccess.tInterface = typeof(IUserObject); oRemoteAccess.cServiceName = "UserObject"; oUserObject = (IUserObject)oRemoteAccess.GetAccessObject(); string cXMLResultSet = oUserObject.ValidateUser(oGlobals.cUserID, oGlobals.cUserPassword, oGlobals.nDataBaseKey); Uses of Interfaces - Kevin S. Goff

  7. Generic Data Binding • Data bound controls work differently • Textbox is bound to different property than a checkbox, and a combobox has more properties • Define data binding interface • Define interfacenamespace CGS.Interfaces { public interface IBoundControl (BindControl, DtSource, DcSource) • Implement interface (PEMs) in data-bound controls • Textbox, combo box (additional properties), checkbox • Implements props of the interface, plus the BindControl method • Each BindControl behaves a little differently, but it doesn’t matter • On a form or container, we can loop through controls and bind easily ((IBoundControl)oControl).BindControl(); Uses of Interfaces - Kevin S. Goff

  8. Reusable data maintenance forms • Generic data maintenance form: • public interface IDataMaintenanceForm • public interface ICriteriaContainer • public interface IResultContainer • public interface IEntryContainer Uses of Interfaces - Kevin S. Goff

More Related