1

I have been given an java assignment in school that requires me to create a StockQuote class. This would normally be easy, however the teacher has referred to it as a simple container class. I'm confused because everything that I read says container classes are things like java.util.Vector, java.util.Hashtable, and java.util.HashSet. I get the feeling he is using this term to mean something else, perhaps even just to mean a strightforward StockQuote class. I tried emailing him but he hasn't responded and I'd like to get a jump on the assignment. Here is the description from the assignment:

"A StockQuote class or interface. This a simple container class. Typically you would not use an interface for container classes, but you could. One rule for when to use an interface or not is to decided if there ever possibly could be more than one implementation of the class. If more than one implementation is possible, then using an interface definitely makes sense. In the case of simple container classes like this one, there probably will only be one implementation"

Any help or nudge in the right direction would be great. Thanks

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Matthew Tuman
  • 59
  • 2
  • 9
  • 1
    You're confusing container and collection – OneCricketeer Feb 01 '18 at 00:59
  • 1
    I assume that `StockQuote` "contains" quotes – MadProgrammer Feb 01 '18 at 00:59
  • 1
    see https://en.wikipedia.org/wiki/Container_(abstract_data_type) – Scary Wombat Feb 01 '18 at 01:00
  • Possible duplicate of [What are the containers in Java](https://stackoverflow.com/questions/1288708/what-are-the-containers-in-java) – Jai Feb 01 '18 at 01:09
  • If this is the only description you received, then it's not very clear what your instructor is expecting. "Container" is a very generic term, but in Java is often understood like in Scary's Wikipedia article: a data structure that can store a variable number of other objects. It's hard to see how that could apply to a class called `StockQuote` (singular), certainly without further detailing. Maybe he means something like "domain object", JavaBean, POJO or the like. – Erwin Bolwidt Feb 01 '18 at 01:51

1 Answers1

1

In your case This a simple container class. == This a simple class..

In general your class may have some fields of other types, like String, Collections, etc. If so, you would say I have a container class because it contains/stores some data. Interfaces don't have fields, so they are not containers.

Dmytro Maslenko
  • 2,247
  • 9
  • 16
  • Thanks I had a feeling that this was the answer. So if the constructor of the StockQuote class utilized dependency injection and injected an object of type StockService (another class in the assignment) into the constructor, StockQuote would be a container class because it contains an object of type StockService...is that correct? – Matthew Tuman Feb 01 '18 at 01:09
  • Yes, it contains something and somehow. But you already ask about aggregation vs composition. See https://stackoverflow.com/questions/1644273/what-is-the-difference-between-aggregation-composition-and-dependency. – Dmytro Maslenko Feb 01 '18 at 01:11