Answer the question
In order to leave comments, you need to log in
Does the following class structure violate OOP and SOLID principles?
Interface description:
export interface NextPrevPage<T> {
prevUrl: string;
nextUrl: string;
getNextPage(): Observable<T>;
getPrevPage(): Observable<T>;
}
export class OrdersDistributionService implements NextPrevPage<Response> {
constructor(private http: HttpClient) {}
prevUrl: string;
nextUrl: string;
getNextPage(): Observable<Response> {
return this.http.get<Response>(this.nextUrl, {});
}
getPrevPage(): Observable<Response> {
return this.http.get<Response>(this.nextUrl, {});
}
getOrders() {}
}
NextPrevPage
into a separate class and use it as a composition inside the OrdersDistributionService service ? Answer the question
In order to leave comments, you need to log in
solid involves working with the architectural layer, and not the design of individual elements that make up the system. In your case, we are talking about design, since the difficulty arose in defining the boundaries of ordinary algorithmic logic in the context of the OOP paradigm.
You have almost everything correct, except for the logic of the urls mixed with the logic of the service. The role of the service in providing the data it downloads over the network, and its responsibilities, its logic should be limited to this. Working with the http service fits into these responsibilities, but there are no links to urls. They are the state of the service itself, which means that working with them is also the logic of the service, which contradicts the logic mixing rule. This situation can be resolved by placing links in a separate object that stores and rotates links.
And you asked about validation. Validation is also placed in a separate validator, and since you are working with rxjs, it happens in the pipe after loading. But keep in mind that if you validate using filter and for some reason the validation fails, the stream will be interrupted and subscribers will never know about it. This behavior will lead to a leak. Therefore, you yourself must manage this.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question