代码之家  ›  专栏  ›  技术社区  ›  remi bourgarel

如何设计管理文件路径的类?

oop
  •  1
  • remi bourgarel  · 技术社区  · 16 年前

    在我的应用程序中,我生成了一些xml文件,例如:“/xml/product/123.xml”,其中123是产品的id,123.xml包含有关该产品的信息。我还有“/xml/customer/123.xml”,其中123.xml包含有关客户端的信息。。。123

    如何管理这些文件路径:

    1. 我直接在序列化方法中创建文件路径?
    2. 我创建了两个静态类:CustomerSerializationPathManager和ProductSerializationPathManager,其中一个方法是getPath(int customerID)和getPath(int productID)
    3. 我创建了一个静态类:SerializationPathManager,它有两个方法:getCustomerPath(int customerID)和getProductPath(int productID)
    4. 还有别的吗

    所以我想听听你的想法。。。谢谢

    1 回复  |  直到 16 年前
        1
  •  1
  •   user159088 user159088    16 年前

    如果需要将文件保存在特定文件夹中,并且这些文件的位置可能会更改,则应将此信息移动到配置文件中,然后再从中使用If。

    然后创建一个类似于工厂的类,使用 getPathForProductExports , getPathForCustomerExports etc读取配置文件以返回所需路径。

    配置文件可以是简单的.properties文件:

    customer_path=/xml/customer/
    product_path=/xml/product/
    

    getPathForCustomerExports获取路径 , getPathForProductExports获取路径 )到文件名。