Design pattern for multiple output formats

后端 未结 7 2204
清酒与你
清酒与你 2021-01-05 04:41

I have a class structure which represents (internally) the data I wish to output to a file.

Some of the member variables are private to the data class so that it ca

7条回答
  •  忘掉有多难
    2021-01-05 05:25

    Don't always resort to friend function because it can easily break the encapsulation of your class. Once friend, it can access all your private members no matter whether you hope it see or not.

    In your case, you can simply provide some public interfaces to return the necessary data to clients which will produce different formats then. Furthermore, you can take a look at famous MVC pattern if you're interested.

提交回复
热议问题