gpt4 book ai didi

Java 类滥用 - 最佳实践

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:39:47 26 4
gpt4 key购买 nike

<分区>

我很确定我没有正确地做一些与类相关的事情。

我正在使用一个类来创建一组变量(有点像 javascript 对象,可能但不是真的)。​​

我正在使用它,如下所示(一个基本示例)

public class myScript {

public static void main(String[] args) {

Client warehouse = new Client();
Contacts warehouseContactsA = new Contacts();
Contacts warehouseContactsB = new Contacts();

warehouse.idno = 1;
warehouse.name = "warehouse";
warehouse.desc = "I don't exist";

warehouseContactsA.client_idno = 1;
warehouseContactsA.email = "emailAAA@place.com"

warehouseContactsB.client_idno = 1;
warehouseContactsB.email = "emailBBB@place.com"

insertIntoDB(warehouse,
warehouseContactsA,
warehouseContactsB);

}

public static void insertIntoDB(Client warehouse,
Contacts warehouseContactsA,
Contacts warehouseContactsB) {

// code to insert into database here

}

private class Client {
int idno;
String name;
String desc;
}

private class Contacts {
int client_idno;
String email;
}

}

是否有任何理由不以这种方式使用类,如果是这样,是否有一种更简单的方法来存储/管理不需要类的数据?

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