Refactor: Visual Studio Extract Interface

I recently learned about a very cool option in Visual Studio, the ability to extract an Interface from an existing class. This has made me much more comfortable in trying to adhere to a principle of not creating unnecessary code. I often found myself thinking I should create an interface first before creating the concrete implementation even for objects that I didn't have any current plans for extending.

This post will show you step by step how to extract an interface from an existing class, so keeping with open closed principle we can still extend the code base with our modifying the current object.

First lets consider the the Attendee class.

namespace Attendee
{
public class Attendee
{
private int _age;
public int Age
{
get { return _age; }
set { _age = value; }
}
private string _firstname;
public string FirstName
{
get { return _firstname; }
set { _firstname = value; }
}
private string _lastName;
public string LastName
{
get { return _lastName; }
set { _lastName = value; }
}

public bool
Save()
{
return true;
}
}
}
 

This is a very simple class implementation of an Attendee, a class I use in my Model-View-Controller presentation. Note this is a very simple domain object with no logic. To extract an interface place your cursor in the class name, Attendee in this case, select Extract Interface... on the Refactor menu.

 

ExtractInterface_01

This will launch the Extract Interface wizard. We can now modify the name, file name and the members to include in the interface.

ExtractInterface_02

Clicking OK after making your selection will generate the interface below.

using System;
namespace Attendee
{
interface IAttendee
{
int Age { get; set; }
string FirstName { get; set; }
string LastName { get; set; }
bool Save();
}
}

Now you are free to create a new implementation of the Attendee class with out having to change any of the code in the old Attendee class. This has really reduced the fear of not creating an interface for everything first. Of course I still do for most of my objects but if there is no reason to create it right now, this give me the confidence that I can defer creating the interface and extension point until it is necessary.

Community Leader Summit

This weekend I attended an awesome event in Dallas, TX, the Community Leader Summit. Soon to become CommunityCamp. Thanks Caleb for organizing this event. There were user groups there represented by a huge cross section of the user community. Everything from .NET to Podcasting, and Joomla. It was very interesting to see that even though our groups are focused on different technologies that we all struggle with the same things. And it was great to see how other groups has solved them. I am sure the next CommunityCamp will be even better as we dive deeper into how to solve these problems and get to making our groups thrive and grow.

University of Arkansas .NET User Group: Lap Around Visual Studio 2008

February 5th, 2008 I had the opportunity to present at the University of Arkansas .NET User Group. I presented a Lap Around Visual Studio 2008 to about 15 member so the group. It was a great experience and I would like to thank Eddie Mahar for the opportunity and thanks to the group that showed up it was a great discussion. Some Major Points from the Presentation:

  1. Visual Studio multi-targeting allows you to easily move up to Visual Studio 2008
  2. LINQ simplifies data access through language extensions for C# & Visual Basic
  3. WF & WCF make it easier to build rich, connected applications using a variety of types of services
  4. WPF Designer provides design-time support for building WPF applications and a streamlined workflow between developers and designers
  5. VSTO enables developers to build Office Business Applications for Office on the client or server
  6. NetCF 3.5 brings major .NET Framework enhancements to mobile devices

If you haven't made the jump to Visual Studio 2008 and would like to, check out my earlier post on how you can try it for free.

Jean-Paul S. Boodhoo Presents at Nwa .NET User Group

One of my colleagues at Tyson Foods arranged to have Jean-Paul S. Boodhoo give a Nothin' But Dot Net Training class.  I saw the opportunity to have him present at our use group since the training was the same week as our meeting.  Jean-Paul was gracious enough to agree to present on Generics: They're no just for collections. He has also agreed to help me launch a Podcast I have been wanting to start called Let's Talk Code!.  Thanks, JP for helping get this started. Generics: They’re not just for collections In this session participants will be introduced to advanced usages of generics outside of the realm of just strongly typed collections. They will learn about how the focus of generics in the realm of collections has clouded the fact that generics can be used to introduce powerful capabilities into your application frameworks and solutions. Practical demonstrations will be utilized to showcase how developers can immediately start harnessing the power of generics in their applications today.

Jean-Paul S. Boodhoo is an independent consultant who spends most of his days helping teams realize success through the adoption and application of agile practices. He has a passion for sharing information with the development community which he often tries to do on his blog at http://www.jpboodhoo.com/blog. He can be reached at jp@jpboodhoo.com. When not developing, he can be found relaxing with his amazing wife and their four beautiful kids.

Calendar

<<  March 2024  >>
MonTueWedThuFriSatSun
26272829123
45678910
11121314151617
18192021222324
25262728293031
1234567

View posts in large calendar

Widget Category list not found.

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))X

Tag cloud

    Widget Month List not found.

    Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))X

    Widget AuthorList not found.

    Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))X

    Widget TextBox not found.

    Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))X