在运行时填充对象字段值属于哪种设计模式
只是心里有一个问题,所以想听听专家的意见。这可能是一个愚蠢的问题。
实际上,我正在使用反射机制在运行时填充类的某些字段值。假设我有一个包含 5 个字段的 A 类。我将在编译时设置 2 个字段的值,但其余三个字段的值将在运行时设置。
所以我的问题是它是否属于某种设计模式?
问候,
马亨德拉·阿瑟内里亚
just having a question in mind so thought lets get the views from expert. it might be a silly question.
Actually i am using Reflection Mechanism to fill the some of the fields value of a class at run time. lets say i have a class A with 5 fields. i'll set the value of 2 fields at compile time but the remaining three fields value i'll set at run time.
So my question is that does it fall under some Design pattern?
Regards,
Mahendra Athneria
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这与 AutoFixture 的做法非常接近。它的内部架构基本上只是一个大的责任链。
Builder 模式也浮现在脑海中。
This is very close to what AutoFixture does. Its internal architecture is basically just a big Chain of Responsibility.
The Builder pattern also comes to mind.
我认为答案取决于您存储的类和对象的语义。它让我想到策略设计模式(strategy_pattern),其中上下文可以保存特定的策略对象。也许这不是你的情况。
I think that the answer depends on the semantic of your class and object stored. It makes me think to strategy design pattern ( strategy_pattern) where the context can hold a particular strategy object. Maybe this isn't your case.