+1
Under review

Could somebody explain me how to use Bridge with Abstrac Factory?

RareScrap 2 lat temu zaktualizowano 2 lat temu 2

The Bridge article says:

"You can use Abstract Factory along with Bridge. This pairing is useful when some abstractions defined by Bridge can only work with specific implementations. In this case, Abstract Factory can encapsulate these relations and hide the complexity from the client code."

But I can't really understand what "specific implementations" are. Does that mean some variation of products? If so, would it be better to get such product from the constructor rather than Abstract Factory? Could somebody give an example of using Bridge with Abstrac Factory?

+1
Under review

Hi!

Suppose you have a Bridge hierarchy like this:

Abstraction: BasicFileSystem → VersionControlFileSystem

Implementations: Fat, NTFS, APFS

One of the abstractions (VersionControlFileSystem) can only work with a specific implementation (NTFS, APFS).

Instead of requiring client to know about this implication when instantiating Abstractions & Implementations, you could provide abstract factory to create necessary classes (and maybe even handle errors when non-existent pairs are requested). Below is a pseudocode:

interface FileSystemFactory {
createBasicFileSystem() → BasicFileSystem
createVersionControlFileSystem() → VersionControlFileSystem
}

class WindowsFileSystemFactory {
createBasicFileSystem() → BasicFileSystem + Fat
createVersionControlFileSystem() → VersionControlFileSystem + NTFS
}

class macOsFileSystemFactory {
createBasicFileSystem() → BasicFileSystem + Fat
createVersionControlFileSystem() → VersionControlFileSystem + APFS
}

Thank you for explanation. I think this should be included in article using some kind of footnote.