View Single Post
Scag
AlliedModders Donor
Join Date: May 2017
Location: Crashing Hale
Old 09-13-2020 , 01:04   Re: ArrayList Class vs. ArrayStack Class
Reply With Quote #2

The most fundamental difference is that an ArrayStack items are FILO/LIFO and ArrayList items can be retrieved/inserted at any index.

Internally, they're exactly the same, an ICellArray. So the question is, why bother with a stack?

When you declare/use either, you are stating what kind of behavior you want. An ArrayList behaving as an ArrayStack is unneeded complexity.

You are telling anyone who looks at your code (including your future self) what it is you are doing and intend to do with this array.

If you want to stretch it, the same argument could be made about private class members/methods. Why bother making something private? Which presents the above answer of enforcing behavior and managing complexity.

Contrary to my signature, I tend to "use the minimum to achieve the maximum" when I code.

FWIW there's also a Queue include you can check out and use.
__________________
Over-engineering is underrated.

GitHub
BTC
ETH

Retired
Scag is offline