Making external types available to mixins

John Chapman johnch_atms at hotmail.com
Sun Nov 18 11:29:51 UTC 2018


On Saturday, 17 November 2018 at 21:11:38 UTC, Adam D. Ruppe 
wrote:
> On Saturday, 17 November 2018 at 17:58:54 UTC, John Chapman 
> wrote:
>> Has anyone had a similar need and come up with a solution?
>
> You might be able to just pass it the Calendar type, and then 
> fetch its parent module and get the ICalendarFactory from there 
> (assuming they are defined in the same module).
>
> But generally speaking, passing strings to a mixin that refer 
> to something in another module isn't going to work well thanks 
> to scoping rules. You are better off passing a symbol of some 
> sort.

So there is no actual Calendar type. There's an ICalendarFactory 
type that creates instances of ICalendar (these types are part of 
a third-party API).  "Calendar" is just a key users could use 
when calling a "makeWith" method that would build the 
ICalendar/Factory names, instantiate the factory, call the 
appropriate factory method and return the result. There are 
thousands of such object/factory pairs in the API. Just trying to 
cut out a lot of boilerplate code, but it doesn't seem doable 
this way.


More information about the Digitalmars-d-learn mailing list