简体   繁体   中英

Who should customize appearance of a CustomUIView

What I would like to ask here is a design question.

I have a CustomUIViewController that handle some subviews inside the controller view.

These two views are logically distinct and have different roles:

  • The first subview contains the UIControl objects the user can interact with (Game Controls).
  • The second subview just shows the game progresses.

The problem is that I need to have multiple Game Controls implementations (let's say two, that can be graphically totally different) and let the user choose the one he prefers.

My question is: will it be considered a good practice to have the CustomUIViewController's code coupled with both the Game Controls implementations (included the graphic assets to use to customize the appearance of each one)? Or would it be better if the appearance setup of the Game Control views is handled by another object (a factory, a delegate or something similar)?

Can you suggest any pattern that can help to handle a use case like this?

Thank you in advance.

I would suggest you to create separate classes for two views which you are going to add on CustomUIViewController . You can then add whatever components and functionalities you want in respective classes. It would be easy to understand the code, you will also feel easy in case you wish to add some extended functionalities to particular subview. Don't put everything in the same class, you might end up messing up the things.

If possible always try to follow MVC Architecure

Subclass the 2 UIView you are trying to use so that you can have 2 custom views than add to your viewcontroller.

By doing this you have a benefit of getting touch events on your custom UIView implementation and it will be an easier approach then putting everything in the same class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM