简体   繁体   中英

Subclassing one of your own classes or using the same parent class?

In my application, I have a mainViewController that has a bunch of letter tile UIImageViews. You can pan the letters around on this mainViewController to spell out words.

I also have popover viewcontrollers that contain letter tiles that you can drag out onto the mainViewController. Once the letter tiles are dropped onto the mainViewController, they need to have access to all the same methods that the letter tiles do that already exist on the mainViewController.

Currently, I create the letter tiles in the mainViewController and the popover viewcontrollers separately. Both the mainViewController and popover viewcontroller's parent classes are UIViewController.

I was wondering if in my situation, I should be declaring all letter tiles contained in my popover viewcontrollers in the mainViewController class, then have the popoverview controllers be a subclass of mainViewController?

If I should change it, can you please tell me why it would be better to?

Thanks!

Objective-C is famous for preferring delegation over subclassing.

I would rather use a datasource class that knows of all the tiles and their methods and use it in both controllers.

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