Skip to content

Using static virtual feature for differing i2c addresses with inheritance.

Notifications You must be signed in to change notification settings

richlander/i2caddress

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

i2caddress -- static abstract interface member

The static abstract interface feature enables us to model specifying i2c addresses (as static methods) and to choose to specify a different value in more derived implementations (like we can do today).

The relevant code:

public interface II2cAddress
{
    static abstract int DefaultI2cAddress { get; }
}

public class Device : II2cAddress
{
    public static int DefaultI2cAddress => 0x70;
}

public class SpecializedDevice : Device
{
}

public class MoreSpecializedDevice : Device, II2cAddress
{
    public static new int DefaultI2cAddress => 0x74;
}

This is what the app looks like:

% dotnet run
Hello, World!
I have three devices, with two specific addresses:
- Device: 070
- SpecializedDevice: 070
- MoreSpecializedDevice: 074

The repo contains both the way we do this today, in the net60 folder and this new way, in the net70 folder.

This PoC is a breaking change on what we have today. It's more a question of whether this is a model we want to adopt as a going forward idea.

About

Using static virtual feature for differing i2c addresses with inheritance.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages