If I remember correctly, back when iOS 7 was released, there were a couple of issues regarding the public API of certain classes which implementation was completely changed. The following is an example of what I mean:

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) 
    [[UINavigationBar appearance] setTintColor: [UIColor colorWithRed:129/255.0 green:200/255.0 blue:244/255.0 alpha:1.0]];
    [[UINavigationBar appearance] setBarTintColor: [UIColor colorWithRed:129/255.0 green:200/255.0 blue:244/255.0 alpha:1.0]];

In this specific example, prior to iOS 7, the correct way to change the color of the navigation bar was through the use of setTintColor. Once iOS 7 was out, not only a new method, setBarTintColor was created for the same purpose, but also, instead of deprecating the previous one, the behavior was modified, causing the breakage of multiple source codes (thus the need of using a conditional if-else to runtime-check the current version and call the right method).

Does this counts as a violation of the Open/Closed Principle?

  • 2
    I don't know if that's the principle it breaks but I can tell you that if Scott Forstall and Steve Jobs were still running the show, such an arbitrary API decision would not have been made. – RibaldEddie Oct 7 '15 at 20:55
  • There is a well known quote "rules are meant to be broken" ... – rwong Oct 8 '15 at 4:01

I'll answer my 3 y/o question by saying that OCP principle has nothing to do with API changes, but abstraction patterns when designing classes.

  • Classes themselves have an API. – Robert Harvey Apr 17 at 16:08
  • And Apple is under no obligation to follow any of the SOLID principles. – Robert Harvey Apr 17 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.