gpt4 book ai didi

java - 这个问题的最佳设计模式

转载 作者:行者123 更新时间:2023-11-29 07:21:13 26 4
gpt4 key购买 nike

我需要构建各种命令并将它们作为参数传递给另一个程序。

这些命令共享一些信息和格式,但参数数量不同。

例如,对于 CRUD 操作,我可能会生成以下命令字符串:

"create""host_ip""database""user_id""profile""personal_data1""personal_data2""personal_datan"
"retrive""host_ip""database""user_id"
"update""host_ip""database""user_id""personal_data1""personal_data2""personal_datan"
"delete""host_ip""database""user_id"

我相信有更聪明的方法来做到这一点,通过在这个令人惊叹的网站上分享它,我可能会做得更好。

最佳答案

也许太明显了,但你有没有想过 Command Pattern?

In object-oriented programming, the command pattern is a design pattern in which an object is used to represent and encapsulate all the information needed to call a method at a later time. This information includes the method name, the object that owns the method and values for the method parameters. Three terms always associated with the command pattern are client, invoker and receiver. The client instantiates the command object and provides the information required to call the method at a later time. The invoker decides when the method should be called. The receiver is an instance of the class that contains the method's code. Using command objects makes it easier to construct general components that need to delegate, sequence or execute method calls at a time of their choosing without the need to know the owner of the method or the method parameters.

关于java - 这个问题的最佳设计模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4227690/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com