{"id":5645,"date":"2012-08-08T16:01:37","date_gmt":"2012-08-08T21:01:37","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=5645"},"modified":"2012-08-08T16:02:25","modified_gmt":"2012-08-08T21:02:25","slug":"why-nsorderedset-doesnt-inherit-from-nsset","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2012\/08\/08\/why-nsorderedset-doesnt-inherit-from-nsset\/","title":{"rendered":"Why NSOrderedSet Doesn&rsquo;t Inherit From NSSet"},"content":{"rendered":"<p><a href=\"http:\/\/www.tomdalling.com\/blog\/software-design\/why-nsorderedset-doesnt-inherit-from-nsset-a-real&#8209;life-example-of-the-liskov-substitution-principle\">Tom Dalling<\/a>:<\/p>\n<blockquote cite=\"http:\/\/www.tomdalling.com\/blog\/software-design\/why-nsorderedset-doesnt-inherit-from-nsset-a-real&#8209;life-example-of-the-liskov-substitution-principle\"><p>There was an interesting question on StackOverflow this morning: <a href=\"http:\/\/stackoverflow.com\/questions\/11278995\/why-doesnt-nsorderedset-inherit-from-nsset\">Why doesn&rsquo;t NSOrderedSet inherit from NSSet?<\/a> It&rsquo;s interesting because the reason is so easy to miss. I thought it would make a good blog post because it turned out to be a nice, real-life example of the <a href=\"http:\/\/www.tomdalling.com\/blog\/software-design\/solid-class-design-the-liskov-substitution-principle\">Liskov substitution principle<\/a> (herein abbreviated to LSP).<\/p><\/blockquote>\n<p>He points to the <code>-mutableCopy<\/code> method, but I think there&rsquo;s a problem with the <code>-isEqual:<\/code> method even when considering only immutable sets. An ordered set wants to include order in its definition of equality, while a regular set cares only about membership. Equality can&rsquo;t be implemented in a way that&rsquo;s symmetric and transitive. Thus, it makes sense for them not to be subtypes.<\/p>","protected":false},"excerpt":{"rendered":"<p>Tom Dalling: There was an interesting question on StackOverflow this morning: Why doesn&rsquo;t NSOrderedSet inherit from NSSet? It&rsquo;s interesting because the reason is so easy to miss. I thought it would make a good blog post because it turned out to be a nice, real-life example of the Liskov substitution principle (herein abbreviated to LSP). [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-5645","post","type-post","status-publish","format-standard","hentry","category-programming-category"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/5645","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=5645"}],"version-history":[{"count":4,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/5645\/revisions"}],"predecessor-version":[{"id":5649,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/5645\/revisions\/5649"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=5645"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=5645"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=5645"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}