Giter Club home page Giter Club logo

Comments (3)

yindz avatar yindz commented on May 28, 2024

谢谢建议。很多数据其实是松散的,难以归类的,我还没有想到一个比较合适的写法。需要一点时间来思考一下。

from common-random.

lunfangyu avatar lunfangyu commented on May 28, 2024

谢谢建议。很多数据其实是松散的,难以归类的,我还没有想到一个比较合适的写法。需要一点时间来思考一下。

嗯,好的。归类暂时可以不做,保持现状就行。后面有更好的想法了再优化归类也可以。
我的意思是增加一个如下入口类:RandomSource,大概如下:

public class RandomSource {

    public EducationSource education() {
        return EducationSource.getInstance();
    }
    
    public PersonInfoSource person() {
        return PersonInfoSource.getInstance();
    }

    // 获取其他资源类……
}

当我需要造假数据时,我只需要这样:

    RandomSource  randomSource = new RandomSource();
    // 随机学校名字
    String schoolName = randomSource.education().randomHighSchoolName();
    // 随机人名
    String personName = randomSource.person().randomChineseName();
    

这样的好处是:使用者只需要记住RandomSource这个主类即可。后面不管增加多少资源类,都可以依赖IDEA的提示功能,知道有哪些资源,然后按需调用即可。参考同类框架组件:Faker.java

而现在,因为没有统一的入口类;我需要去查看文档到底有哪些资源类(EducationSource、PersonInfoSource);然后再获取对应资源类的实例后才可以获取数据。

不知道我表达得是否清楚。

from common-random.

yindz avatar yindz commented on May 28, 2024

谢谢建议。很多数据其实是松散的,难以归类的,我还没有想到一个比较合适的写法。需要一点时间来思考一下。

嗯,好的。归类暂时可以不做,保持现状就行。后面有更好的想法了再优化归类也可以。 我的意思是增加一个如下入口类:RandomSource,大概如下:

public class RandomSource {

    public EducationSource education() {
        return EducationSource.getInstance();
    }
    
    public PersonInfoSource person() {
        return PersonInfoSource.getInstance();
    }

    // 获取其他资源类……
}

当我需要造假数据时,我只需要这样:

    RandomSource  randomSource = new RandomSource();
    // 随机学校名字
    String schoolName = randomSource.education().randomHighSchoolName();
    // 随机人名
    String personName = randomSource.person().randomChineseName();
    

这样的好处是:使用者只需要记住RandomSource这个主类即可。后面不管增加多少资源类,都可以依赖IDEA的提示功能,知道有哪些资源,然后按需调用即可。参考同类框架组件:Faker.java

而现在,因为没有统一的入口类;我需要去查看文档到底有哪些资源类(EducationSource、PersonInfoSource);然后再获取对应资源类的实例后才可以获取数据。

不知道我表达得是否清楚。

最终还是要看源码啊。不过谢谢你的建议,我后续加上。

from common-random.

Related Issues (13)

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.