Hi guys, I wonder if you can help.
As I've started as a programmer, I've been told I have to practice OO a bit more. I've done the theory, but I think I will have to take another look at it. , Above all though, I have to do exercises.
What I'm looking for is for suggestions: things I have to practice are:
-Inheritance
-Interfaces
-Polymorphism
-And in general anything to do with OO.
Ideally I don't really need to do any complicated exercise, even simple scenarios would do as long as I can put into practice the theory, printing some user input strings might be enough as long as I can implement 00 principles, so things like, an emplyoee hierarchy or something along these lines.
Also I know Im a bit weak when it comes to linking different classes together, and things like composition.
So, can anybody suggest simple situation/s I could use to practice?
I have installed the Spring Tool Suite but if I'm not mistaken I can use it to create ordinary java projects.
Any idea?

If you're just looking for ideas I've gone one at least one: a program to import (scrape I guess?) web sites like the steam store and amazon to collect meta data for different games (include a way to specify sites to get data from). Something like having an input box to enter a game or importing a one-per-line text file list (or CSV, whatever) and the program collects all the data from whatever sites it can find it on along along with screenshots and ratings.
Something like an generic game object and off of that genre, release date, rating, value (from price charts or etc), platform, system requirements etc. You could implement inheritance for creating different sorts of game objects and DLC as the child object. Then also a convenient export feature to JSON/XML/CSV.
Doesn't have to be Windows games of course. You could use movies, music, or whatever else. I just happen to be experiencing some frustrations related to certain game database software and lack of Windows game meta data I've been thinking about it a lot.
I don't know if this is what you had in mind. I am really a noob to programming so I'm sorry if this didn't help.

It's certainly an idea, but I'm not sure if I'm actually capable of doing that, I'll give it some thought

There are lots of real-world collections of objects that relate to other types of objects in different ways. A very obvious example would be Organism, with subclasses Animal, Plant, etc.. The Animal class would contain Vertebrate and Invertebrate classes. Within the Vertebrate class you have Mammals, Reptiles, Fish, etc. then each of these classes has it's subclasses. Each class would have its attributes, which would be the data members. You can get as in depth as you like with more and more attributes, more and more animals. All animals must eat. You can keep track of what each Animal type can eat, and what each Animal can be eaten by in a Vector or whatever works. Then you have an Ecosystem which contains a Collection of Organisms. A collection of verbs like "eats" and "sleeps" and "reproduces" and "dies" can be placed in an Interface.

As an example, I have an Ecosystem. Part of that Ecosystem is a a Collection of Organisms. I have a Mammal class. That Mammal class must implement "eats", "sleeps", "reproduces", and "dies", so I stick those functions into an Interface called StuffMammalsDo. Or maybe it belongs in the StuffVertebratesDo. Or StuffCarnivoresDo. Study up on biology and stick things in the correct class. As always, as you go, you'll move things around. For example, let's say I have a Cat, Dog, Lion, and Rabbit class. They all Eat. But Cats, Dogs, and Lions are Carnivores and Rabbits are Herbivores. All are Mammals. I have a function: void eats(Cat cat) in my StuffRabbitsDo Interface and my Rabbit class must implement StuffRabbitsDo. So I have this code:

Rabbit rabbit = new Rabbit();
Cat cat = new Cat();
rabbit.eats(cat);

Then I look at this code and decides it makes no sense. It would make sense in the StuffLionsDo interface, but not in the StuffRabbitsDo interface. So I change my eats function to voideats(Plant plant);.

    Rabbit rabbit = new Rabbit();
   Carrot carrot = new Carrot();
    rabbit.eats(carrot); // much better

What happens when the rabbit eats a carrot? There's now one less carrot in the Ecosystem or wherever the rabbit lives. Let's say the rabbit lives on a Farm and you have a Farm class and part of that class is keeping track of whatever Organisms live there. So the Farm has a Set of Organisms which reside on the Farm. when something is eaten, that something is removed from that Set. So change the eats() function to take a Farm as a parameter: void eats(Plant plant, Farm farm)

void eats(Plant plant, Farm farm)
{
    farm.getLivingOrganisms().remove(plant);
}

The "dies" function would likely work in a similar way. Or maybe when something dies, you have other Animals i.e. Scavengers eat it first. And each Animal has a certain amount of time that it can go with out food until It dies and the "eats" function resets that clock. Or...

What you have is an ecosystem that is as complex or as simple as you want. You set up classes and interfaces and change them around till it makes sense. Whenever you want to, you can add more Organism types and add things that they can do. The sky's the limit.

That's just one example. Think of anything that can be categorized into different types of Objects with shared attributes and shared things that they do, and how they interact. How they interact is your Interface. How they relate to each other is your Class structure. What attributes go where determines each class's data members.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.