8000 建议增加一个统一入口类 · Issue #67 · yindz/common-random · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

建议增加一个统一入口类 #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lunfangyu opened this issue Nov 11, 2022 · 3 comments
Closed

建议增加一个统一入口类 #67

lunfangyu opened this issue Nov 11, 2022 · 3 comments

Comments

@lunfangyu
Copy link

看到这个框架感觉很惊喜,使用效果也非常好。
但使用过程也碰到了一点小小的问题:
第一次使用时,不知道该使用哪个类生成什么样的数据。这点可以通过查找文档解决,但还是有点麻烦。
所以我建议,能否个Java Faker那样增加一个总的入口类(Faker),比如叫RandomSource,由此类可以获取到com.apifan.common.random 包下的所有资源类;这样在IDEA强大的提示功能下,即使是初次使用的人,也可以大大减少查找文档,提高效率。

以上,仅个人愚见。

@yindz
Copy link
Owner
yindz commented Nov 12, 2022

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

@lunfangyu
Copy link
Author

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

嗯,好的。归类暂时可以不做,保持现状就行。后面有更好的想法了再优化归类也可以。
我的意思是增加一个如下入口类: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);然后再获取对应资源类的实例后才可以获取数据。

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

@yindz
Copy link
Owner
yindz commented Nov 13, 2022

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

嗯,好的。归类暂时可以不做,保持现状就行。后面有更好的想法了再优化归类也可以。 我的意思是增加一个如下入口类: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);然后再获取对应资源类的实例后才可以获取数据。

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

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

@yindz yindz closed this as completed Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0