.NET Tip: Take Advantage of Interfaces Houston TX

Stop writing more code than needed. You can streamline your code if you use interfaces. You will be able to write simpler, more flexible, and more maintainable applications when you apply interfaces.

Local Companies

Entrance Software
713-357-4930
1001 McKinney
Houston, TX
ObjectWin Technology, Inc.
(713) 337-1834
2650 Fountain View Drive, Suite 405
Houston, TX
Delta Business Solutions
(281) 445-3600
525 N. Sam Houston PKWY E
Houston, TX
Silicus Techologies
(713) 353-7416
Gray Falls
Houston, TX
Palindrome Software Labs Ltd
206-366-5542
7700 WillowChase BLVD
Houston, TX
NuHire Recruiting Solutions
281-748-9990
17002 Nautical Pointe Ln
Houston, TX
Essential Technology Group
(713) 524-8111
3701 Kirby Dr Ste 978
Houston, TX
Saic
(713) 626-4848
1900 West Loop S Ste 650
Houston, TX
Core Technology Group the
(281) 855-7891
Houston, TX
Information Advantage Associates
(713) 977-7691
3000 Wilcrest Dr
Houston, TX

provided by: 
Originally published at Internet.com


Take advantage of interfaces to make your code cleaner and more reusable. A simple example of where interfaces can be applied is in populating UI controls. How many ListBox controls do you have to populate in your web application? One solution is to write the code to populate each ListBox individually in the Page_Load method. Another method could be to create a helper method that takes an array of data items and a ListBox as parameters, populating the ListBox from the array of data. Here is an example of such a method. private void LoadListBox(object[] data, ListBox ListBoxControl) { for (int i = 0; i < data.Length; i++) ListBoxControl.Items.Add(data[i].ToString()); }

With the LoadListBox method in place, the code to populate the ListBox in the Page_Load method is simplified. string[] TestItems = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; LoadListBox(TestItems, ListBox1);

Although this is better than doing all the work in the Page_Load method, you can do much better. This works fine for a ListBox, but what about other list type controls? If you apply interfaces, you can enhance the helper method to support a variety of data sources and list type controls. Instead of the helper method taking an array of data items and a ListBox control, it now takes an ICollection and a ListControl. private void LoadListControlFromCollection(ICollection data, ListControl ListControlControl) { foreach (object item in data) ListControlControl.Items.Add(item.ToString()); }

Usage of the new LoadListControlFromCollection method to load a ListBox with data items remains the same. string[] TestItems = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; LoadListControlFromCollection(TestItems, ListBox1);

The advantage of the new method, however, is that you also can apply it to other list type controls. The flexibility is evident when you use the same method to populate a CheckListBox, DropDownList, RadioButtonList, or BulletList. LoadListControlFromCollection(TestItems, CheckBoxList1); LoadListControlFromCollection(TestItems, DropDownList1); LoadListControlFromCollection(TestItems, RadioButtonList1); LoadListControlFromCollection(TestItems, BulletedList1);

Applying the use of interfaces can make your applications simpler and more flexible. If you take a look through your code, I bet you can find several places where your application would benefit from using interfaces. Start thinking about interfaces today; the person who comes behind you and has to maintain your code will thank you.

About the Author

Jay Miller is a Software Engineer with Electronic Tracking Systems, a company dedicated to robbery prevention, apprehension, and recovery based in Carrollton, Texas. Jay has been working with .NET since the first beta's release and is co-author of Learn Microsoft Visual Basic.Net In a Weekend. Jay can be reached via email at jmiller@sm-ets.com.

Author: Jay Miller

Read article at Internet.com site

Featured Local Company

Entrance Software

Entrance Software is a Software Development and Consulting company and a Microsoft Gold Certified Partner.

713-357-4930
1001 McKinney
Houston, TX
http://www.entrancesoftware.com

For mid-sized businesses that own or need software, Entrance Software is a Trusted Advisor. Unlike other contract programming or staffing companies, Entrance exclusively provides Professional Software Consultants who are not only technical geniuses, but also understand the business value of Sales, Profit, Productivity, Loyalty and Morale.

Entrance Software is a Microsoft Gold Certified Partner and develops custom software applications for businesses in a variety of industries including Oil and Gas, Exploration and Production, Manufacturing, Education, Legal and Medical Services.


Related Local Events
Deep Offshore Technology (DOT 2010)
Dates: 2/2/2010 - 2/4/2010
Location: George R. Brown Convention Center
Houston, TX
View Details

Subsea Tieback Exhibition (SSTB)
Dates: 3/2/2010 - 3/4/2010
Location: Moody Gardens Hotel & Convention Center
Galveston, TX
View Details

2009 IEEE Industry Applications Society Annual Meeting
Dates: 10/4/2009 - 10/7/2009
Location: Hyatt Regency Houston
Houston, TX
View Details