Skip to content
This repository was archived by the owner on May 12, 2022. It is now read-only.
This repository was archived by the owner on May 12, 2022. It is now read-only.

Extract the external calls for a facade class #18

@wesleyfuchter

Description

@wesleyfuchter

Wouldn't make sense to use the Facade design pattern to extract the external calls for a separated class and import that class on the other dart code that uses it. The logic behind it to call the C function is ugly and extracting for a single class would make your code better.

class OpenMtpLookupFacade {
    
    final DynamicLibrary dyLib;
    const OpenMtpLookupFacade() {
         dyLib = DynamicLibrary.open(libraryPath);
    }
    
    void openModFile(String file) {
        final OpenModFile openModFileC = dyLib.lookup<NativeFunction<openModFile_native>>('open_mod_file').asFunction();
        openModFileC(file.toNativeUtf8());
    }

}

and in the other places:

final openMtp = OpenMtpLookupFacade();
openMtp.openModFile(myFancyString);

For the clients of this class the FFI is totally transparent, they won't know you're calling C :D

final OpenModFile openModFileC = dyLib.lookup<NativeFunction<openModFile_native>>('open_mod_file').asFunction();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions