Category: .NET
Animated iPhone-style ImageButton with Silverlight 4
| July 5, 2011 | Posted by Matt under .NET, Silverlight |
In this article I am presenting a way to create animated iPhone-style ImageButton control in Silverlight 4. Button will have icon on it, rounded corners and will zoom-in/zoom-out on hover. It will be done programmatically, with very minimum amount of XAML. I start with creating ImageButton class. I use ButtonBase as base class: I want…
Using Sets in .Net
| June 27, 2011 | Posted by Matt under .NET |
Great post by James Michael Hare I came across about using Sets in .Net. Definitely worth taking a look. http://geekswithblogs.net/BlackRabbitCoder/archive/2011/02/03/c.net-little-wonders-the-useful-but-overlooked-sets.aspx
WCF Custom tool error: Failed to generate code for the service reference.
| June 23, 2011 | Posted by Matt under .NET, WCF, Web |
Very recently, building multi-tier application involving Silverlight front-end inter-operating with WCF back-end, I encountered very odd, yet annoying behaviour of Visual Studio 2010. I was building new functionality using Telerik RadMap for Silverlight control that was to display some spartial data supplied by WCF service. To achieve this my Silverlight application had to reference few…
SQL Data Types vs. C# Data Types
| April 15, 2011 | Posted by Matt under .NET, SQL |
This article is just a reference of SQL Data Types to C# Data Types. SQL Server data type CLR data type (SQL Server) CLR data type (.NET Framework) varbinary SqlBytes, SqlBinary Byte[] binary SqlBytes, SqlBinary Byte[] varbinary(1), binary(1) SqlBytes, SqlBinary byte, Byte[] image None None varchar None None char None None nvarchar(1), nchar(1) SqlChars, SqlString…
Interface vs. Abstract Class in .Net
| November 26, 2010 | Posted by Matt under .NET |
In this article I will try to briefly explain main differences between interface and abstract class concepts in .Net. Although the differences can appear to be very subtle and little important, badly design inheritance can lead to massive problems and great mess in the code. Abstract Class Accordingly to MSDN abstract classes “are classes that…
public class OffRoadCar : Car { public OffRoadCar(); public void Switch4WD(bool On) { // method code }; }
Because class OffRoadCar inherits from Car, following code will work:
OffRoadCar offroader = new OffRoadCar(); offroader.Switch4WD(true); // from OffRoadClass offroader.Drive(); // from Car class
Interface
Interface, after MSDN, is a “definition that can never change after the interface definition has been released. This interface invariance is an important principle of component design, because it protects existing systems that have been written to use the interface.”
Interface cannot be instantiated, but serve as sort of pattern for derived classes, that share and implement specific features. Derived classes can also extend interface functionality, by defining extra members. Following code demonstrates sample interface:
public interface ICar { string Make { get; set; } void Drive(); }
Because interface can serve as a “template” for series of classes, implementing it is a way of ensuring that all derived object will have set of common features. In example:
public class SportsCar : ICar { public string Make { get; set; } // required from ICar public bool IsConvertible { get; set; } // adds extra feature public void Drive() // required by ICar { }; } public class Van : ICar { public string Make { get; set; } // required from ICar public double LoadWeight { get; set; } // adds extra feature public void Drive() // required by ICar { }; }
Because both SportsCar and Van classes inherit from ICar interface, they are forced to have common set of features (Make property and Drive() method). Thanks to that it is possible to write:
List<ICar> vehicles = new { new SportsCar() { Make = "Ferrari", IsConvertible = false }, new Van() { Make = "Ford", LoadWeight = 3000 } }; foreach(ICar car in vehicles) { Console.WriteLine(car.Make); }
Conclusion
In opposite to abstract class, interface cannot implement any default functionality in its methods. It also cannot implement default constructor. This is why we say we implement interface and inherit from abstract class.
Class may implement an unlimited number of interfaces, but may inherit from only one abstract class. A class that is derived from an abstract class may still implement interfaces.
Abstract classes and interfaces play extremely important role in programming concept called polymorphism, which in essence is “ability for classes to provide different implementations of methods that are called by the same name” (MSDN).
I am IT professional with over 10 years of experience in computer programming and web development, specializing in Microsoft technologies.



Recent Comments