A project that I am working on has the following code for interface example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Test
{
public interface IDeviceEssentials
{
string Model { get; set; }
string Manufacturer { get; set; }
string BIOSVersion { get; set; }
string TotalPhysicalMemory { get; set; }
string TotalVirtualmemory { get; set; }
string OSName { get; set; }
}
}
every other class implementing this interface uses Automatic properties which renders the getters and setters useless so the effective implementation is reduced to
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Test
{
public interface IDeviceEssentials
{
string Model;
string Manufacturer;
string BIOSVersion;
string TotalPhysicalMemory;
string TotalVirtualmemory;
string OSName;
}
}
For which simply a structure or class is enough to hold the data..
The main usage of interface is polymorphism making use of liskov substitution, even though the above code is using the getter setter it is effectively reduced to variable decleration by all the classes implementing it (by using automatic property). That is there is no need i want to mock the above interface. even if it is designed as a class I can simply mock by creating new class of it.
Question are :-
- I think the above properties are providing data representation only. is it ok to use interface only for data representation?