Giter VIP home page Giter VIP logo

Comments (4)

seongahjo avatar seongahjo commented on September 25, 2024

@esfomeado
The issue I understand is that you need a new option to determine the implementation of the interface dynamically.
Is it right?

In order to define an interface, we need to know which implementations are actually available.
I think there are two ways.

  1. Specify the package in which the implementation exists
  2. Specify the implementations just like interfaceImplements

Any other ideas?

from fixture-monkey.

esfomeado avatar esfomeado commented on September 25, 2024

Yes, correct.

How would option 1 work if for instance there are multiple classes on that package that are not implementations of the interface? Will it handle sub packages as well?

My initial plan was to use reflection to get all the available implementations for the interface.

from fixture-monkey.

seongahjo avatar seongahjo commented on September 25, 2024

@esfomeado
How about making a custom ObjectPropertyGenerator or using existing ObjectPropertyGenerator?

public final class InterfaceObjectPropertyGenerator<T> implements ObjectPropertyGenerator {

If you use reflection to get all the available implementations and then make your own InterfaceObjectPropertyGenerator.

You could use pushAssignableTypeObjectPropertyGenerator option.

pushObjectPropertyGenerator(
    new MatherOperator<>(
        p -> Modifier.isAbstract(Types.getActualType(p.getType()).getModifiers()), 
        new CustomObjectPropertyGenerator()
    )
);

In this case, You could use third-party library. https://github.com/ronmamo/reflections/

from fixture-monkey.

esfomeado avatar esfomeado commented on September 25, 2024

@seongahjo Thanks. That's literally what I wanted.

Works like a charm

from fixture-monkey.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.