Maps/OOP: Difference between revisions
From charlesreid1
(→Flags) |
(→Flags) |
||
| Line 40: | Line 40: | ||
[[Category:OOP]] | [[Category:OOP]] | ||
[[Category: | [[Category:Interface]] | ||
[[Category:Inheritance]] | [[Category:Inheritance]] | ||
[[Category: | [[Category:Comparable]] | ||
[[Category:Maps]] | [[Category:Maps]] | ||
[[Category: | [[Category:Java]] | ||
Revision as of 07:26, 26 June 2017
Notes
This page describes the application of object oriented principles to the Maps / Dictionaries data type.
- Start by describing the inheritance diagram
- Then describe the use of OOP principles - comparators, iterables, and encapsulation
- Composition design pattern for utility classes
- How to use binary search to find keys in an ArrayList containing composite objects
Inheritance Diagram
The top-level base class is the Map interface class, which defines public behaviors that Map objects must expose.
The next level down is the Abstract Map class, which defines a few private behaviors and some utility classes.
The SortedArrayMap and UnsortedArrayMap share quite a bit of code and should probably inherit from an ArrayMap base class, but they do not. They fulfill all the requirements of the Maps/ADT Maps abstract data type.
Map interface
AbstractMap abstract class
Array map class
The base behavior here would be, defining the private field (ArrayList) that stores the key-value items, and define some of the other behavior that follows from that concrete implementation (size, iterators, etc.)
Unsorted
To implement the map using an unsorted array of key-value pairs, the add method becomes very simple - we just stick the value at the end. The remove method is only slightly more complicated - we perform a sequential search to find the element of interest, remove it, and move the last item in the array to the open slot.
Sorted
To implement the map using a sorted array of key-value pairs, we need to be able to translate between the type the user passes (the key type) and the type of objects in the array (key-value item type). Once we have a way of directly comparing the key and the key-value items, we can use the binary search function from the Collections class to find where in the ArrayList the key is located (or where it should be inserted, if it is not already in the list).
Flags
| Maps and Dictionaries Part of Computer Science Notes
Series on Data Structures
Maps/Dictionaries Maps · Maps/ADT · Maps in Java · Maps/OOP · Maps/Operations and Performance Map implementations: Maps/AbstractMap · Maps/UnsortedArrayMap · Maps/SortedArrayMap Dictionary implementations: Dictionaries/LinkedDict · Dictionaries/ArrayDict
Hashes Hash Maps/OOP · Hash Maps/Operations and Performance Hash Maps/Dynamic Resizing · Hash Maps/Collision Handling with Chaining Hash functions: Hash Functions · Hash Functions/Cyclic Permutation Hash map implementations: Hash Maps/AbstractHashMap · Hash Maps/ChainedHashMap
Skip Lists · Java/ConcurrentSkipList · Java implementations: SkipList
Sets Sets · Sets/ADT · Sets in Java · Sets/OOP · Multisets
|