Solid in Flutter
Solid in Flutter
SOLID IN FLUTTER
Swipe for more info
eTechViral 02
just like each room in your house has its own set of tools
and applications, each class in your codebase should
have its own set of methods and properties that are
related to the class’s purpose
Example: Suppose we have a class called user which is responsible for storing
user data. This class should not be responsible for sending an email or any
other unrelated tasks. Instead, we can create a separate class called
EmailSender to handle the Email sending task.
class user {
String name;
String email;
String password;
class emailSender{
}
eTechViral 04
void processPayment();
void processPayment() {
void processPayment() {
}
eTechViral 05
Example: Suppose we have a class called Animal and its subclass called Dog. If
we have a method that accepts an Animal object, we should be able to pass a
Dog object to that method without causing any issues.
class Animal {
void main() {
void makesound() {
Animal animal = Animal();
print(‘Animal sound’);
Dog dog = Dog();
}
makeAnimalSound(animal);
}
// print ’Animnalsound’
void makesound() {
makeAnimalSound(Dog); // Pprint ‘Bark’
print(‘bark’);
}
}
animal.sound();
eTechViral 06
Example: Suppose we have interface class printer and another interface called
scanner. The MultiFunctionPrinter class implements both interfaces, but the
LaserPrinter class only implements that printer interface. This way, a client can
use the LaserPrinter class without being forced to implement the
scanDocument method which is not relevant in this case.
void printDocument();
// scan document
}
}
void scanDocuments();
class LaserPrinter implements Printer {
}
void printDocument() {
printer, scanner {
void printDocument() {
}
// Prind document
}
07
eTechViral
void processPayment();
void prosessPayment() {
void processPayment() {
class paymentprocessor {
PaymentGatway _getway;
PaymentProcessor(this._gateway);
void PaymentProcessor() {
_gateway.processPayment();
eTechViral 09
DO YOU FIND
THIS POST
USEFUL?
FOLLOW FOR MORE