.NET Tip: Take Advantage of Interfaces Orlando FL

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

Longview Solutions Inc
407-246-1030
135 N Magnolia Ave
Orlando, FL
Perceptive Technologies
(321) 206-5999
37 N. Orange Ave. Suite 810
Orlando, FL
Aspire Solution
407-894-5560
2909 Fairgreen St
Orlando, FL
Cam Commerce Solutions
407-774-8098
4449 Lipton CT
Orlando, FL
Riptide Software
407-384-8818
3452 Lake Lynda Dr
Orlando, FL
Tapestry Solutions
407-482-0270
3361 Rouse Rd
Orlando, FL
Acusoft
407-658-9888
11869 High Tech Ave
Orlando, FL
Progressive System Solutions Inc
407-523-7676
4019 Clarcona Ocoee RD
Orlando, FL
Group One Software
407-248-0998
7380 W Sand Lake Rd
Orlando, FL
Miller Software Systems Inc
407-354-5433
8504 Cedar Cove CT
Orlando, FL

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

Longview Solutions Inc

407-246-1030
135 N Magnolia Ave
Orlando, FL

Related Local Events
PERFORMANCE RACING INDUSTRY SHOW 2009
Dates: 12/10/2009 - 12/12/2009
Location: Orange County Convention Center
Orlando, FL
View Details

American Rental Association Annual Convention and Rental Trade Show
Dates: 2/8/2010 - 2/11/2010
Location: Orange County Convention Center
Orlando, FL
View Details

Pittcon - Pittsburgh Conference and Exposition on Analytical Chemistry and Applied Spectroscopy
Dates: 3/1/2010 - 3/1/2010
Location: Orange County Convention Center
Orlando, FL
View Details

OOPSLA '09: ACM SIGPLAN Object Oriented Programming Systems and Applications Conference
Dates: 10/19/2009 - 10/23/2009
Location: Disney Coronado Springs Resort
Lake Buena Vista, FL
View Details

2009 3rd International Symposium on Empirical Software Engineering and Measurement (ESEM)
Dates: 10/15/2009 - 10/16/2009
Location: Hilton Walt Disney World Resort
Lake Buena Vista, FL
View Details