Ardeshir ojan
Ardeshir ojan

Reputation: 2419

why do we use abstract classes in clean architecture?

we have abstract classes in clean architecture where we just define functions and then write the whole code in an implementation class that implements those functions. why not use only the second function?

abstraction

abstract class PriceTrackerDataSource {
  Stream<dynamic> getActiveSymbols();
}

implementation

class PriceTrackerDataSourceImpl implements PriceTrackerDataSource {
  @override
  Stream<dynamic> getActiveSymbols() async* {
    if (_ws != null) {
      await _ws!.sink.close();
    }

    _connect();
    yield* _ws!.stream;
  }

Upvotes: 1

Views: 838

Answers (2)

voselo
voselo

Reputation: 91

Abstract classes are used to make each layers more independent (data, domain, presentation). And also to define main methods for the own classes

Upvotes: 1

Yash Garg
Yash Garg

Reputation: 589

Abstract classes help us to define a template / common definition for our multiple derived classes also reducing code duplication.

Making the class abstract ensures that it cannot be used on its own, but the details must be defined in the derived class implementation.

For more explanation you can have a look at Dart Docs.

Upvotes: 0

Related Questions