Avatar of pnoeric
pnoericFlag for United States of America asked on

A question of OOP conventions, not actual code: Where should I put this method?

Here's just a general question about coding convention, I'm not sure how to award points on this, maybe I'll just give them to what I think is the most interesting answer :-)

I have some code with two classes: one dealing with CDs, the other dealing with lists.

I am writing a new method to put a CD on a list, another method to remove a CD from a list, etc.

Do the methods go in the CD class? Or the list class?

Programming TheoryAlgorithms

Avatar of undefined
Last Comment

8/22/2022 - Mon


The list should be generic, so it should not know anything about what stores.
A CD must know just what it is, and nothing about its brothers or where it's living.
You should write a third class like an adapter responsible to store CDs, something like CDManager; that class should have a List of CDs, and will let you store, delete, sort, paint, and all you wanna do with CDs.
That class will divide the storing from the rest of the logic of your software.

Just to think about it.

I hope it will be useful for you.


Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Hi again

The logics to store, delete, and iterate must be in the list, but think about where to store ol the logic to manage CDs.
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.

I believe that you should implement a design pattern. There are many that you could choose from. But naturally without implementing a pattern i would be inclined to put things about the cd in the cd class , and same for lists. Look into the MVC pattern and adapt it to your application.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.

hi ,
i think i am sure to say method should be in the list class
assume every person will have something lets say an ArrayList(java syntax) of the CDs ,
so removing any CD from that list should be unique for every person.