A
A
Anton R.2019-10-01 19:03:34
OOP
Anton R., 2019-10-01 19:03:34

What is better to use here? Simple inheritance, interfaces, or even an abstract class?

In general, in my bulletin board there are a lot of places where a certain List of ads is displayed, namely:
- Class fresh ads on the Main
- Class my ads in my account
- Class my favorite ads (other people's ads that I added to Favorites)
- Class ads by category (displays a list of ads of a certain category)
So, all these classes have one thing in common - they are all Lists, and these lists essentially display the same ad cards (judging by the fields: picture, title, price), but these lists are displayed based on different conditions, that is, each list will have an individual set of elements.
What is better to use here? Inherit all these classes from the abstract AdvertsList class? Or can it make an interface with the getAdvertsList method and each class implements it in its own way (on its own terms)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2019-10-01
@Maksclub

a bunch of places where a list of ads is displayed

Use a declaration list DTO (or an array) that consists of a list of declaration DTOs. Only 1 per se class to display

N
Northern Lights, 2019-10-03
@php666

post the code in a separate topic, you ask a lot of questions, it’s obvious that you are trying, but you are stubbornly driving somewhere in the wrong direction in architecture ... you need to see what you are doing, maybe they will help you get rid of bad architecture in advance.
And you didn't read Fowler's chapter on data sources, did you?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question