Skip to content

Enhancement: Abstract I2CBuilder and SPIBuilder #209

Open
@EAGrahamJr

Description

@EAGrahamJr

To ensure more consistency across devices, I would suggest that the I2CBuilder and SPIBuilder classes get some abstraction. For example:

public abstract class AbstractI2CBuilder<I2CThing> {
    protected int controller;
    protected int address;
    protected I2CDeviceInterface device;
    protected I2CThing thing;

    protected abstract I2CThing buildThing(I2CDeviceInterface i2CDeviceInterface);

    public I2CThing build() {
        if (thing == null) {
            if (device == null) device = I2CDevice.builder(address).setController(controller).build();
            thing = buildThing(device);
        }
        return thing;
    }
}

This would help ensure behavior across all the device classes using these builders, as there currently is some variation depending upon when the class was added to the code base (i.e. some builders throw exceptions when the device is already created and others do not)1.

I didn't find a whole lot of current devices that have "dual interfaces", so there may not be a lot of refactoring involved, but would likely help for future additions.

1Not a criticism by any means -- my own stuff gets out of date within days. 😏

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions