-
Notifications
You must be signed in to change notification settings - Fork 8
Resolve Issues #21, #23, and #24 #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ntainers#24 - Enhance Null Object Pattern and Simplify API
|
Hi @pankaj-bind Thnx for the PR but I was already working on explicit check issue ( as discussed in #22 ) & was almost ready with PR. However if Stephan thinks this implementation is ok we can merge it. |
|
@pankaj-bind I don't have any problem with your PR ( just inform from next time that you are interested ). |
|
So how de we proceed? Do we merge this PR? @Alokzh @pankaj-bind ? it looks good to me |
|
Could we use a singleton for this code? CTAVLNilNode newto CTAVLNilNode uniqueInstance |
|
@jordanmontt wait I must check concern of @Alokzh and @akevalion |
|
Looks good to me Jordan |
|
Hey @akevalion yes you could use a singleton for CTAVLNilNode to save memory, but it’s not necessary and risks future complexity unless justified by performance needs. |
|
Looks good for me, I will merge it |
Issue #21: About NilNode
Problem: CTAVLNode methods like childrenDo:, do:, height, and isBalanced contain explicit ifNil: checks, which you noted could be avoided with a proper Null Object pattern.
Fix: Enhanced CTAVLNilNode to implement all necessary methods (e.g., childrenDo:, do:, height) with no-op or default behavior, and removed ifNil: checks from CTAVLNode methods, relying on polymorphism.
Issue #23: Can we get rid of isNilNode
Problem: CTAVLTree >> size uses isNilNode to check if the root is a CTAVLNilNode, which is unnecessary with a Null Object pattern.
Fix: Removed isNilNode from the class hierarchy, introduced a polymorphic nodeSize method (0 for CTAVLNilNode, recursive count for CTAVLNode), and refactored CTAVLTree >> size to simply call root nodeSize.
Issue #24: Can we get rid of AVLTree >> isNil
Problem: CTAVLTree >> isNil checks if the root is a CTAVLNilNode, which you questioned as redundant for a tree’s API.
Fix: Removed CTAVLTree >> isNil, relying on isEmpty (inherited from Collection) which uses size = 0, made possible by the nodeSize refactoring.