├── .gitignore ├── .idea ├── .gitignore ├── libraries │ └── Dart_SDK.xml ├── misc.xml ├── modules.xml └── vcs.xml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── analysis_options.yaml ├── bin ├── 1-creational_patterns │ ├── 1-singleton │ │ ├── singletone.dart │ │ └── singletone_main.dart │ ├── 2-prototype │ │ ├── 1-prototype.dart │ │ ├── 2-temp_employee.dart │ │ ├── address.dart │ │ └── prototype_main.dart │ ├── 3-builder │ │ ├── 1-product.dart │ │ ├── 2-builder.dart │ │ ├── 3-car.dart │ │ ├── 4-motor_cycle.dart │ │ ├── 5-director.dart │ │ └── builder_main.dart │ ├── 4-factory_method │ │ ├── 1-bank_interface.dart │ │ ├── 2-bank_a.dart │ │ ├── 3-bank_b.dart │ │ ├── 4-bank_factory_interface.dart │ │ ├── 5-bank_factory.dart │ │ └── factory_main.dart │ └── 5-abstract_factory │ │ ├── 1-bank │ │ ├── 1-bank_interface.dart │ │ ├── 2-bank_a.dart │ │ └── 3-bank_b.dart │ │ ├── 2-payment │ │ ├── 1-payment_interface.dart │ │ ├── 2-visa.dart │ │ └── 3-master_card.dart │ │ ├── 3-bank_factory_interface.dart │ │ ├── 4-bank_factory.dart │ │ └── abstract_factory_main.dart └── 2-structural_patterns │ ├── 1-proxy │ ├── 1-i_sms_service.dart │ ├── 2-sms_service.dart │ ├── 3-proxy_sms.dart │ └── proxy_main.dart │ ├── 2-decorator │ ├── 1-abstract_decorator.dart │ ├── 2-notificaion_email_decorator.dart │ └── decorator_main.dart │ ├── 3-adapter │ ├── 1-employee.dart │ ├── 2-machine_operator.dart │ ├── 3-salary_calculator.dart │ ├── 4-salary_adapter.dart │ └── adapter_main.dart │ ├── 4-facade │ ├── 1-basket_item.dart │ ├── 2-shopping_basket.dart │ ├── 3-inventory.dart │ ├── 4-inventory_order.dart │ ├── 5-purchase_invoice.dart │ ├── 6-payment_processor.dart │ ├── 7-sms_notification.dart │ ├── 9-purchase_order.dart │ └── facade_main.dart │ ├── 5-flyweight │ ├── 1-i_discount_calc.dart │ ├── 2-day_discount.dart │ ├── 3-item_discount.dart │ ├── 4-discount_factory.dart │ └── flyweight_main.dart │ └── 6-composite │ ├── 1-arithmetic_exp.dart │ ├── 2-numeric_operand.dart │ ├── 3-composite_operand.dart │ └── composite_main.dart ├── design_patterns_dart.iml ├── lib └── design_patterns_dart.dart ├── pubspec.lock ├── pubspec.yaml └── test └── design_patterns_dart_test.dart /.gitignore: -------------------------------------------------------------------------------- 1 | # Files and directories created by pub. 2 | .dart_tool/ 3 | .packages 4 | 5 | # Conventional directory for build output. 6 | build/ 7 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/libraries/Dart_SDK.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.0.0 2 | 3 | - Initial version. 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Mina Faried 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | A sample command-line application with an entrypoint in `bin/`, library code 2 | in `lib/`, and example unit test in `test/`. 3 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the static analysis results for your project (errors, 2 | # warnings, and lints). 3 | # 4 | # This enables the 'recommended' set of lints from `package:lints`. 5 | # This set helps identify many issues that may lead to problems when running 6 | # or consuming Dart code, and enforces writing Dart using a single, idiomatic 7 | # style and format. 8 | # 9 | # If you want a smaller set of lints you can change this to specify 10 | # 'package:lints/core.yaml'. These are just the most critical lints 11 | # (the recommended set includes the core lints). 12 | # The core lints are also what is used by pub.dev for scoring packages. 13 | 14 | include: package:lints/recommended.yaml 15 | 16 | # Uncomment the following section to specify additional rules. 17 | 18 | # linter: 19 | # rules: 20 | # - camel_case_types 21 | 22 | # analyzer: 23 | # exclude: 24 | # - path/to/excluded/files/** 25 | 26 | # For more information about the core and recommended set of lints, see 27 | # https://dart.dev/go/core-lints 28 | 29 | # For additional information about configuring this file, see 30 | # https://dart.dev/guides/language/analysis-options 31 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/1-singleton/singletone.dart: -------------------------------------------------------------------------------- 1 | class Singleton { 2 | //parent-child relation ship 3 | static Singleton? singleton; 4 | int counter = 0; 5 | 6 | static Singleton getInstance() { 7 | singleton ??= Singleton(); 8 | return singleton!; 9 | } 10 | 11 | void addOne() { 12 | counter++; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/1-singleton/singletone_main.dart: -------------------------------------------------------------------------------- 1 | import 'singletone.dart'; 2 | 3 | main() { 4 | ///hasCode is same location in memory 5 | Singleton singleton = Singleton.getInstance(); 6 | print(singleton.hashCode); 7 | Singleton singleton1 = Singleton.getInstance(); 8 | print(singleton1.hashCode); 9 | Singleton singleton2 = Singleton.getInstance(); 10 | print(singleton2.hashCode); 11 | 12 | singleton.addOne(); 13 | singleton1.addOne(); 14 | singleton2.addOne(); 15 | print( 16 | "object counter is ${singleton.counter} ${singleton1.counter} ${singleton2.counter}"); 17 | } 18 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/2-prototype/1-prototype.dart: -------------------------------------------------------------------------------- 1 | import 'address.dart'; 2 | 3 | abstract class EmployeePrototype { 4 | int? id; 5 | String? name; 6 | Address? empAddress; 7 | 8 | EmployeePrototype shallowCopy(); 9 | EmployeePrototype deepCopy(); 10 | 11 | @override 12 | String toString() { 13 | return 'EmployeePrototype {\nid: $id,\nname: $name,\nempAddress: ${empAddress.toString()}\n}'; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/2-prototype/2-temp_employee.dart: -------------------------------------------------------------------------------- 1 | import '1-prototype.dart'; 2 | import 'address.dart'; 3 | 4 | class TempEmployee extends EmployeePrototype { 5 | @override 6 | EmployeePrototype shallowCopy() { 7 | return this; 8 | } 9 | 10 | @override 11 | EmployeePrototype deepCopy() { 12 | TempEmployee emp = TempEmployee(); 13 | //this address is reference type 14 | emp.empAddress = Address( 15 | building: empAddress?.building, 16 | street: empAddress?.street, 17 | city: empAddress?.city, 18 | ); 19 | emp.name = name; 20 | emp.id = id; 21 | return emp; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/2-prototype/address.dart: -------------------------------------------------------------------------------- 1 | class Address { 2 | String? building, street, city; 3 | 4 | Address({this.building, this.street, this.city}); 5 | 6 | @override 7 | String toString() { 8 | return 'Address{\nbuilding: $building,\nstreet: $street,\ncity: $city}'; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/2-prototype/prototype_main.dart: -------------------------------------------------------------------------------- 1 | import '1-prototype.dart'; 2 | import '2-temp_employee.dart'; 3 | import 'address.dart'; 4 | 5 | void main() { 6 | EmployeePrototype tempEmp1 = TempEmployee(); 7 | tempEmp1.name = "temp1"; 8 | tempEmp1.id = 1; 9 | tempEmp1.empAddress = 10 | Address(city: "city 1", building: "B1", street: "street 1 "); 11 | 12 | ///try deep and shallow here 13 | EmployeePrototype tempEmp2 = tempEmp1.deepCopy(); 14 | 15 | print("emp1 hash code ${tempEmp1.hashCode}"); 16 | print("emp2 hash code ${tempEmp2.hashCode}"); 17 | 18 | print("================ Temp Emp 1 Original Values =============="); 19 | print(tempEmp1.toString()); 20 | print("================ Temp Emp 2 Copy =============="); 21 | print(tempEmp2.toString()); 22 | 23 | print("===============Change1+================="); 24 | tempEmp2.empAddress?.street = "new Street1"; 25 | tempEmp2.id = 2; 26 | tempEmp2.name = "temp 2"; 27 | print("================ Temp Emp 1 after change=============="); 28 | print(tempEmp1.toString()); 29 | print("================ Temp Emp 2 =============="); 30 | print(tempEmp2.toString()); 31 | print("emp1 hash code ${tempEmp1.hashCode}"); 32 | print("emp2 hash code ${tempEmp2.hashCode}"); 33 | } 34 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/3-builder/1-product.dart: -------------------------------------------------------------------------------- 1 | import 'dart:collection'; 2 | 3 | class string extends LinkedListEntry { 4 | final String str; 5 | 6 | string(this.str); 7 | 8 | @override 9 | String toString() { 10 | return str; 11 | } 12 | } 13 | 14 | class Product { 15 | LinkedList parts = LinkedList(); 16 | 17 | void add(string part) { 18 | parts.add(part); 19 | } 20 | 21 | String show() { 22 | StringBuffer result = StringBuffer(); 23 | result.write("product components are :"); 24 | for (string part in parts) { 25 | result.write("\n${part.toString()}"); 26 | } 27 | return result.toString(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/3-builder/2-builder.dart: -------------------------------------------------------------------------------- 1 | import '1-product.dart'; 2 | 3 | abstract class Builder { 4 | void startUpOperations(); 5 | 6 | void buildBody(); 7 | 8 | void insertWheels(); 9 | 10 | void addHeadLights(); 11 | 12 | void endOperations(); 13 | 14 | Product getVehicle(); 15 | } 16 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/3-builder/3-car.dart: -------------------------------------------------------------------------------- 1 | import '1-product.dart'; 2 | import '2-builder.dart'; 3 | 4 | class CarBuilder extends Builder { 5 | late Product product; 6 | late String brandName; 7 | 8 | CarBuilder(this.brandName) { 9 | product = Product(); 10 | } 11 | 12 | @override 13 | void startUpOperations() { 14 | product.add(string("car model name : $brandName")); 15 | } 16 | 17 | @override 18 | void buildBody() { 19 | product.add(string("body of car was added")); 20 | } 21 | 22 | @override 23 | void insertWheels() { 24 | product.add(string("wheels of car was added")); 25 | } 26 | 27 | @override 28 | void addHeadLights() { 29 | product.add(string("headlights of car was added")); 30 | } 31 | 32 | @override 33 | void endOperations() {} 34 | 35 | @override 36 | Product getVehicle() { 37 | return product; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/3-builder/4-motor_cycle.dart: -------------------------------------------------------------------------------- 1 | import '1-product.dart'; 2 | import '2-builder.dart'; 3 | 4 | class MotorCycleBuilder extends Builder { 5 | late Product product; 6 | late String brandName; 7 | 8 | MotorCycleBuilder(this.brandName) { 9 | product = Product(); 10 | } 11 | 12 | @override 13 | void startUpOperations() { 14 | product.add(string("car model name : $brandName")); 15 | } 16 | 17 | @override 18 | void buildBody() { 19 | product.add(string("body of car was added")); 20 | } 21 | 22 | @override 23 | void insertWheels() { 24 | product.add(string("wheels of car was added")); 25 | } 26 | 27 | @override 28 | void addHeadLights() { 29 | product.add(string("headlights of car was added")); 30 | } 31 | 32 | @override 33 | void endOperations() {} 34 | 35 | @override 36 | Product getVehicle() { 37 | return product; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/3-builder/5-director.dart: -------------------------------------------------------------------------------- 1 | import '2-builder.dart'; 2 | 3 | class Director { 4 | late Builder builder; 5 | 6 | void construct(Builder builder) { 7 | this.builder = builder; 8 | builder.startUpOperations(); 9 | builder.buildBody(); 10 | builder.insertWheels(); 11 | builder.addHeadLights(); 12 | builder.endOperations(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/3-builder/builder_main.dart: -------------------------------------------------------------------------------- 1 | import '1-product.dart'; 2 | import '2-builder.dart'; 3 | import '3-car.dart'; 4 | import '4-motor_cycle.dart'; 5 | import '5-director.dart'; 6 | 7 | void main() { 8 | Director director = Director(); 9 | Builder carBuilder = CarBuilder("Jeep"); 10 | Builder motorCycleBuilder = MotorCycleBuilder("Honda"); 11 | 12 | /// making car 13 | director.construct(carBuilder); 14 | Product car = carBuilder.getVehicle(); 15 | print("Car ${car.show()}"); 16 | print( 17 | "====================================================================="); 18 | 19 | /// making car 20 | director.construct(motorCycleBuilder); 21 | Product motorCycle = motorCycleBuilder.getVehicle(); 22 | print("MotorCycle ${motorCycle.show()}"); 23 | } 24 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/4-factory_method/1-bank_interface.dart: -------------------------------------------------------------------------------- 1 | abstract class BankInterface { 2 | String withdraw(); 3 | } 4 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/4-factory_method/2-bank_a.dart: -------------------------------------------------------------------------------- 1 | import '1-bank_interface.dart'; 2 | 3 | class BankA extends BankInterface { 4 | @override 5 | String withdraw() { 6 | return "Your request is handling by BankA"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/4-factory_method/3-bank_b.dart: -------------------------------------------------------------------------------- 1 | import '1-bank_interface.dart'; 2 | 3 | class BankB extends BankInterface { 4 | @override 5 | String withdraw() { 6 | return "Your request is handling by BankB"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/4-factory_method/4-bank_factory_interface.dart: -------------------------------------------------------------------------------- 1 | import '1-bank_interface.dart'; 2 | 3 | abstract class BankFactoryInterface { 4 | BankInterface getBank(String code); 5 | } 6 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/4-factory_method/5-bank_factory.dart: -------------------------------------------------------------------------------- 1 | import '1-bank_interface.dart'; 2 | import '2-bank_a.dart'; 3 | import '3-bank_b.dart'; 4 | import '4-bank_factory_interface.dart'; 5 | 6 | class BankFactory extends BankFactoryInterface { 7 | @override 8 | BankInterface getBank(String code) { 9 | switch (code) { 10 | case "111111": 11 | return BankA(); 12 | case "222222": 13 | return BankB(); 14 | default: 15 | return BankA(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/4-factory_method/factory_main.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | import '1-bank_interface.dart'; 4 | import '5-bank_factory.dart'; 5 | 6 | void main() { 7 | BankFactory bankFactory = BankFactory(); 8 | String code = (stdin.readLineSync()!).substring(0, 6); 9 | BankInterface bank1 = bankFactory.getBank(code); 10 | print(bank1.withdraw()); 11 | String code2 = (stdin.readLineSync()!).substring(0, 6); 12 | BankInterface bank2 = bankFactory.getBank(code2); 13 | print(bank2.withdraw()); 14 | } 15 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/5-abstract_factory/1-bank/1-bank_interface.dart: -------------------------------------------------------------------------------- 1 | abstract class BankInterface { 2 | String withdraw(); 3 | } 4 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/5-abstract_factory/1-bank/2-bank_a.dart: -------------------------------------------------------------------------------- 1 | import '1-bank_interface.dart'; 2 | 3 | class BankAA extends BankInterface { 4 | @override 5 | String withdraw() { 6 | return "Your request is handling by BankA"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/5-abstract_factory/1-bank/3-bank_b.dart: -------------------------------------------------------------------------------- 1 | import '1-bank_interface.dart'; 2 | 3 | class BankBB extends BankInterface { 4 | @override 5 | String withdraw() { 6 | return "Your request is handling by BankB"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/5-abstract_factory/2-payment/1-payment_interface.dart: -------------------------------------------------------------------------------- 1 | abstract class PaymentCardInterface { 2 | String getName(); 3 | String getProviderInfo(); 4 | } 5 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/5-abstract_factory/2-payment/2-visa.dart: -------------------------------------------------------------------------------- 1 | import '1-payment_interface.dart'; 2 | 3 | class Visa extends PaymentCardInterface { 4 | @override 5 | String getName() { 6 | return "Visa Card"; 7 | } 8 | 9 | @override 10 | String getProviderInfo() { 11 | return "Visa"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/5-abstract_factory/2-payment/3-master_card.dart: -------------------------------------------------------------------------------- 1 | import '1-payment_interface.dart'; 2 | 3 | class MasterCard extends PaymentCardInterface { 4 | @override 5 | String getName() { 6 | return "Master Card"; 7 | } 8 | 9 | @override 10 | String getProviderInfo() { 11 | return "MasterCard"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/5-abstract_factory/3-bank_factory_interface.dart: -------------------------------------------------------------------------------- 1 | import '1-bank/1-bank_interface.dart'; 2 | import '2-payment/1-payment_interface.dart'; 3 | 4 | abstract class BankFactoryInterface { 5 | BankInterface getBank(String code); 6 | PaymentCardInterface getPaymentMethod(String code); 7 | } 8 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/5-abstract_factory/4-bank_factory.dart: -------------------------------------------------------------------------------- 1 | import '1-bank/1-bank_interface.dart'; 2 | import '1-bank/2-bank_a.dart'; 3 | import '1-bank/3-bank_b.dart'; 4 | import '2-payment/1-payment_interface.dart'; 5 | import '2-payment/2-visa.dart'; 6 | import '2-payment/3-master_card.dart'; 7 | import '3-bank_factory_interface.dart'; 8 | 9 | class BankFactory extends BankFactoryInterface { 10 | @override 11 | BankInterface getBank(String code) { 12 | switch (code) { 13 | case "111111": 14 | return BankAA(); 15 | case "222222": 16 | return BankBB(); 17 | default: 18 | return BankAA(); 19 | } 20 | } 21 | 22 | @override 23 | PaymentCardInterface getPaymentMethod(String code) { 24 | switch (code) { 25 | case "12": 26 | return Visa(); 27 | case "34": 28 | return MasterCard(); 29 | default: 30 | return MasterCard(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /bin/1-creational_patterns/5-abstract_factory/abstract_factory_main.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | import '1-bank/1-bank_interface.dart'; 4 | import '2-payment/1-payment_interface.dart'; 5 | import '4-bank_factory.dart'; 6 | 7 | void main() { 8 | BankFactory bankFactory = BankFactory(); 9 | String code = (stdin.readLineSync()!).substring(0, 6); 10 | BankInterface bank1 = bankFactory.getBank(code); 11 | print(bank1.withdraw()); 12 | String code2 = (stdin.readLineSync()!).substring(0, 2); 13 | PaymentCardInterface paymentCard = bankFactory.getPaymentMethod(code2); 14 | print(paymentCard.getName()); 15 | } 16 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/1-proxy/1-i_sms_service.dart: -------------------------------------------------------------------------------- 1 | abstract class ISMSService { 2 | String sendSMS(String customerId, String mobile, String sms); 3 | } 4 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/1-proxy/2-sms_service.dart: -------------------------------------------------------------------------------- 1 | import '1-i_sms_service.dart'; 2 | 3 | class SMSService extends ISMSService { 4 | @override 5 | String sendSMS(String customerId, String mobile, String sms) { 6 | return "sms sent to $customerId form $mobile and sms : $sms"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/1-proxy/3-proxy_sms.dart: -------------------------------------------------------------------------------- 1 | import '2-sms_service.dart'; 2 | 3 | class ProxySMS { 4 | SMSService? _smsService; 5 | final Map _sentCount = {}; 6 | String sendSMS(String customerId, String mobile, String sms) { 7 | _smsService ??= SMSService(); 8 | 9 | //first call 10 | if (!_sentCount.containsKey(customerId)) { 11 | _sentCount[customerId] = 1; 12 | return _smsService!.sendSMS(customerId, mobile, sms); 13 | } else { 14 | if (_sentCount[customerId]! >= 3) { 15 | return "Not Send it is ended"; 16 | } else { 17 | _sentCount[customerId] = _sentCount[customerId]! + 1; 18 | return _smsService!.sendSMS(customerId, mobile, sms); 19 | } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/1-proxy/proxy_main.dart: -------------------------------------------------------------------------------- 1 | import '3-proxy_sms.dart'; 2 | 3 | void main() { 4 | /** 5 | * proxy types : 6 | * 1- remote proxy (like creating object that calls a web service and hide it's implementation from the client ) 7 | * 2- virtual proxy (like dealing with data bases ) 8 | * 3- protection proxy (like api get way) 9 | * 10 | * */ 11 | ProxySMS sms = ProxySMS(); 12 | print(sms.sendSMS("1234", "0120730018", "hi my name is mino")); 13 | print(sms.sendSMS("1234", "0120730018", "hi my name is mino")); 14 | print(sms.sendSMS("1234", "0120730018", "hi my name is mino")); 15 | print(sms.sendSMS("1234", "0120730018", "hi my name is mino")); 16 | } 17 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/2-decorator/1-abstract_decorator.dart: -------------------------------------------------------------------------------- 1 | import '../1-proxy/1-i_sms_service.dart'; 2 | 3 | class Decorator extends ISMSService { 4 | ISMSService? _notificationService; 5 | 6 | void setService(ISMSService value) { 7 | _notificationService = value; 8 | } 9 | 10 | @override 11 | String sendSMS(String customerId, String mobile, String sms) { 12 | if (_notificationService != null) { 13 | return _notificationService!.sendSMS(customerId, mobile, sms); 14 | } else { 15 | return "NotificationService has not been initialized! "; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/2-decorator/2-notificaion_email_decorator.dart: -------------------------------------------------------------------------------- 1 | import '1-abstract_decorator.dart'; 2 | 3 | class EmailNotificationDecorator extends Decorator { 4 | String sentSmsNotification(String customerId, String sms) { 5 | return "sms '$sms' sent to '$customerId' at ${DateTime.now().toString()}"; 6 | } 7 | 8 | @override 9 | String sendSMS(String customerId, String mobile, String sms) { 10 | StringBuffer result = StringBuffer(); 11 | result.writeln(super.sendSMS(customerId, mobile, sms)); 12 | result.writeln(sentSmsNotification(customerId, sms)); 13 | 14 | return result.toString(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/2-decorator/decorator_main.dart: -------------------------------------------------------------------------------- 1 | import '../1-proxy/1-i_sms_service.dart'; 2 | import '../1-proxy/2-sms_service.dart'; 3 | import '1-abstract_decorator.dart'; 4 | import '2-notificaion_email_decorator.dart'; 5 | 6 | void main() { 7 | ISMSService smsService = SMSService(); 8 | Decorator emailNotification = EmailNotificationDecorator(); 9 | emailNotification.setService(smsService); 10 | 11 | print(emailNotification.sendSMS("1234", "0120730018", "hi my name is mino")); 12 | print(emailNotification.sendSMS("1234", "0120730018", "hi my name is mino")); 13 | print(emailNotification.sendSMS("1234", "0120730018", "hi my name is mino")); 14 | print(emailNotification.sendSMS("1234", "0120730018", "hi my name is mino")); 15 | } 16 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/3-adapter/1-employee.dart: -------------------------------------------------------------------------------- 1 | class Employee { 2 | String? _name; 3 | double? _basicSalary; 4 | 5 | String get name => _name!; 6 | 7 | set name(String value) { 8 | _name = value; 9 | } 10 | 11 | double get basicSalary => _basicSalary!; 12 | 13 | set basicSalary(double value) { 14 | _basicSalary = value; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/3-adapter/2-machine_operator.dart: -------------------------------------------------------------------------------- 1 | class MachineOperator { 2 | String? _name; 3 | String? _shiftCode; 4 | double? _basicSalary; 5 | 6 | String get name => _name!; 7 | 8 | String get shiftCode => _shiftCode!; 9 | 10 | double get basicSalary => _basicSalary!; 11 | 12 | set name(String value) { 13 | _name = value; 14 | } 15 | 16 | set basicSalary(double value) { 17 | _basicSalary = value; 18 | } 19 | 20 | set shiftCode(String value) { 21 | _shiftCode = value; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/3-adapter/3-salary_calculator.dart: -------------------------------------------------------------------------------- 1 | import '1-employee.dart'; 2 | 3 | class SalaryCalculator { 4 | double calcSalary(Employee employee) => employee.basicSalary * 1.5; 5 | } 6 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/3-adapter/4-salary_adapter.dart: -------------------------------------------------------------------------------- 1 | import '1-employee.dart'; 2 | import '2-machine_operator.dart'; 3 | import '3-salary_calculator.dart'; 4 | 5 | class SalaryAdapter extends SalaryCalculator { 6 | Employee? employee; 7 | 8 | double calcSalaryAdapter(MachineOperator operator) { 9 | employee ??= Employee(); 10 | employee!.basicSalary = operator.basicSalary; 11 | return super.calcSalary(employee!); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/3-adapter/adapter_main.dart: -------------------------------------------------------------------------------- 1 | import '1-employee.dart'; 2 | import '2-machine_operator.dart'; 3 | import '3-salary_calculator.dart'; 4 | import '4-salary_adapter.dart'; 5 | 6 | void main() { 7 | Employee employee = Employee(); 8 | employee.name = "name"; 9 | employee.basicSalary = 1000; 10 | 11 | SalaryCalculator calculator = SalaryCalculator(); 12 | print(calculator.calcSalary(employee)); 13 | 14 | MachineOperator operator = MachineOperator(); 15 | operator.basicSalary = 2000; 16 | // print(calculator.calcSalary(operator)); //error 17 | 18 | SalaryAdapter adapter = SalaryAdapter(); 19 | print(adapter.calcSalaryAdapter(operator)); 20 | } 21 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/4-facade/1-basket_item.dart: -------------------------------------------------------------------------------- 1 | class BasketItem { 2 | String? id; 3 | double? price; 4 | double? quantity; 5 | } 6 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/4-facade/2-shopping_basket.dart: -------------------------------------------------------------------------------- 1 | import '1-basket_item.dart'; 2 | 3 | class ShoppingBasket { 4 | List items = []; 5 | 6 | void addItem(BasketItem item) { 7 | items.add(item); 8 | } 9 | 10 | void removeOneItem(String id) { 11 | BasketItem item = items.firstWhere((element) => element!.id == id)!; 12 | if (item.quantity! > 0) { 13 | item.quantity = item.quantity! - 1; 14 | } 15 | } 16 | 17 | List getItems() => items; 18 | } 19 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/4-facade/3-inventory.dart: -------------------------------------------------------------------------------- 1 | class Inventory { 2 | bool checkItemQuantity(String id, double quantity) { 3 | return (quantity < 100); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/4-facade/4-inventory_order.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import '2-shopping_basket.dart'; 4 | 5 | class InventoryOrder { 6 | String createOrder(ShoppingBasket basket, String info) { 7 | basket.getItems(); 8 | return "order number is ${Random().nextInt(100)} for $info"; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/4-facade/5-purchase_invoice.dart: -------------------------------------------------------------------------------- 1 | import '1-basket_item.dart'; 2 | import '2-shopping_basket.dart'; 3 | 4 | class PurchaseInvoice { 5 | double discount = 0; 6 | double totalAmount = 0; 7 | double netTotal = 0; 8 | 9 | PurchaseInvoice createInvoice(ShoppingBasket basket, String customerInfo) { 10 | var invoice = PurchaseInvoice(); 11 | var items = basket.getItems(); 12 | 13 | for (BasketItem? item in items) { 14 | invoice.totalAmount += item!.price! * item.quantity!; 15 | } 16 | 17 | if (items.length > 5) { 18 | invoice.discount = 20; 19 | } 20 | 21 | invoice.netTotal = invoice.totalAmount - invoice.discount; 22 | 23 | return invoice; 24 | } 25 | 26 | @override 27 | String toString() { 28 | return 'PurchaseInvoice{discount: $discount, totalAmount: $totalAmount, netTotal: $netTotal}'; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/4-facade/6-payment_processor.dart: -------------------------------------------------------------------------------- 1 | class PaymentProcessor { 2 | bool handlePayment(double amount, String bankInfo) { 3 | return true; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/4-facade/7-sms_notification.dart: -------------------------------------------------------------------------------- 1 | class SmsNotification { 2 | void sendSms(String to, String msg) {} 3 | } 4 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/4-facade/9-purchase_order.dart: -------------------------------------------------------------------------------- 1 | import '2-shopping_basket.dart'; 2 | import '3-inventory.dart'; 3 | import '4-inventory_order.dart'; 4 | import '5-purchase_invoice.dart'; 5 | import '6-payment_processor.dart'; 6 | import '7-sms_notification.dart'; 7 | 8 | class PurchaseOrder { 9 | String createOrder(ShoppingBasket basket, String customerInfo) { 10 | bool isAvailable = true; 11 | Inventory inventory = Inventory(); 12 | 13 | //check if item exist in inventory 14 | for (var item in basket.getItems()) { 15 | if (!inventory.checkItemQuantity(item!.id!, item.quantity!)) { 16 | isAvailable = false; 17 | } 18 | } 19 | 20 | if (isAvailable) { 21 | StringBuffer result = StringBuffer("$customerInfo\n"); 22 | //create inventory 23 | InventoryOrder inventoryOrder = InventoryOrder(); 24 | result.write("${inventoryOrder.createOrder(basket, "123")}\n"); 25 | 26 | //create invoice 27 | PurchaseInvoice purchaseInvoice = PurchaseInvoice(); 28 | PurchaseInvoice invoice = purchaseInvoice.createInvoice( 29 | basket, "address: 123,id: 456,email: mino@gmail.com"); 30 | result.write(invoice.toString()); 31 | 32 | //payment 33 | PaymentProcessor payment = PaymentProcessor(); 34 | payment.handlePayment(invoice.netTotal, "acc : 1234567"); 35 | 36 | //send sms 37 | SmsNotification smsNotification = SmsNotification(); 38 | smsNotification.sendSms('123', 'INVOICE CREATED'); 39 | return result.toString(); 40 | } 41 | return "not valid"; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/4-facade/facade_main.dart: -------------------------------------------------------------------------------- 1 | import '1-basket_item.dart'; 2 | import '2-shopping_basket.dart'; 3 | import '9-purchase_order.dart'; 4 | 5 | void main() { 6 | ShoppingBasket basket = ShoppingBasket(); 7 | 8 | basket.addItem(BasketItem() 9 | ..id = "123" 10 | ..quantity = 3 11 | ..price = 50); 12 | 13 | basket.addItem(BasketItem() 14 | ..id = "123" 15 | ..quantity = 3 16 | ..price = 50); 17 | 18 | PurchaseOrder order = PurchaseOrder(); 19 | print(order.createOrder(basket, "name: mina,bank:23456,mobile:01000000 ")); 20 | } 21 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/5-flyweight/1-i_discount_calc.dart: -------------------------------------------------------------------------------- 1 | abstract class IDiscountCalc { 2 | double getDiscount(DateTime currentDate, String? itemId); 3 | } 4 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/5-flyweight/2-day_discount.dart: -------------------------------------------------------------------------------- 1 | import '1-i_discount_calc.dart'; 2 | 3 | class DayDiscountCalc extends IDiscountCalc { 4 | @override 5 | double getDiscount(DateTime currentDate, String? itemId) { 6 | return 0.15; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/5-flyweight/3-item_discount.dart: -------------------------------------------------------------------------------- 1 | import '1-i_discount_calc.dart'; 2 | 3 | class ItemDiscountCalc extends IDiscountCalc { 4 | @override 5 | double getDiscount(DateTime currentDate, String? itemId) { 6 | return 0.10; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/5-flyweight/4-discount_factory.dart: -------------------------------------------------------------------------------- 1 | import '1-i_discount_calc.dart'; 2 | import '2-day_discount.dart'; 3 | import '3-item_discount.dart'; 4 | 5 | class DiscountFactory { 6 | Map cache = {}; 7 | 8 | IDiscountCalc getDiscount(String calcType) { 9 | late IDiscountCalc calculator; 10 | 11 | if (cache.containsKey(calcType)) { 12 | return cache[calcType]!; 13 | } 14 | switch (calcType) { 15 | case 'day': 16 | calculator = DayDiscountCalc(); 17 | break; 18 | case 'item': 19 | calculator = ItemDiscountCalc(); 20 | break; 21 | } 22 | 23 | cache[calcType] = calculator; 24 | print(calcType); 25 | 26 | return calculator; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/5-flyweight/flyweight_main.dart: -------------------------------------------------------------------------------- 1 | import '4-discount_factory.dart'; 2 | 3 | void main() { 4 | DiscountFactory discount = DiscountFactory(); 5 | 6 | var calculator1 = discount.getDiscount("day"); 7 | var calculator2 = discount.getDiscount("day"); 8 | var calculator3 = discount.getDiscount("item"); 9 | var calculator4 = discount.getDiscount("item"); 10 | 11 | print(calculator1.hashCode); 12 | print(calculator2.hashCode); 13 | print(calculator4.hashCode); 14 | print(calculator3.hashCode); 15 | 16 | print(discount.cache); 17 | } 18 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/6-composite/1-arithmetic_exp.dart: -------------------------------------------------------------------------------- 1 | abstract class ArithmeticExpression { 2 | double getValue(); 3 | } 4 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/6-composite/2-numeric_operand.dart: -------------------------------------------------------------------------------- 1 | import '1-arithmetic_exp.dart'; 2 | 3 | class NumericOperand extends ArithmeticExpression { 4 | late double value; 5 | 6 | NumericOperand(this.value); 7 | 8 | @override 9 | double getValue() { 10 | return value; 11 | } 12 | 13 | void setValue(double value) { 14 | this.value = value; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/6-composite/3-composite_operand.dart: -------------------------------------------------------------------------------- 1 | import '1-arithmetic_exp.dart'; 2 | 3 | class CompositeOperand extends ArithmeticExpression { 4 | late ArithmeticExpression firstExp; 5 | late ArithmeticExpression secondExp; 6 | late String sign; 7 | 8 | CompositeOperand(this.firstExp, this.sign, this.secondExp); 9 | 10 | @override 11 | double getValue() { 12 | switch (sign) { 13 | case '+': 14 | return firstExp.getValue() + secondExp.getValue(); 15 | case '-': 16 | return firstExp.getValue() - secondExp.getValue(); 17 | case '*': 18 | return firstExp.getValue() * secondExp.getValue(); 19 | case '/': 20 | return firstExp.getValue() / secondExp.getValue(); 21 | default: 22 | return 0; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /bin/2-structural_patterns/6-composite/composite_main.dart: -------------------------------------------------------------------------------- 1 | import '1-arithmetic_exp.dart'; 2 | import '2-numeric_operand.dart'; 3 | import '3-composite_operand.dart'; 4 | 5 | void main() { 6 | ArithmeticExpression exp1 = NumericOperand(3); 7 | ArithmeticExpression exp2 = 8 | CompositeOperand(NumericOperand(3), '+', NumericOperand(2)); 9 | ArithmeticExpression exp3 = CompositeOperand(exp1, '*', exp2); 10 | print(exp2.getValue()); 11 | } 12 | -------------------------------------------------------------------------------- /design_patterns_dart.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /lib/design_patterns_dart.dart: -------------------------------------------------------------------------------- 1 | int calculate() { 2 | return 6 * 7; 3 | } 4 | -------------------------------------------------------------------------------- /pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | _fe_analyzer_shared: 5 | dependency: transitive 6 | description: 7 | name: _fe_analyzer_shared 8 | url: "https://pub.dartlang.org" 9 | source: hosted 10 | version: "48.0.0" 11 | analyzer: 12 | dependency: transitive 13 | description: 14 | name: analyzer 15 | url: "https://pub.dartlang.org" 16 | source: hosted 17 | version: "5.0.0" 18 | args: 19 | dependency: transitive 20 | description: 21 | name: args 22 | url: "https://pub.dartlang.org" 23 | source: hosted 24 | version: "2.3.1" 25 | async: 26 | dependency: transitive 27 | description: 28 | name: async 29 | url: "https://pub.dartlang.org" 30 | source: hosted 31 | version: "2.9.0" 32 | boolean_selector: 33 | dependency: transitive 34 | description: 35 | name: boolean_selector 36 | url: "https://pub.dartlang.org" 37 | source: hosted 38 | version: "2.1.0" 39 | collection: 40 | dependency: transitive 41 | description: 42 | name: collection 43 | url: "https://pub.dartlang.org" 44 | source: hosted 45 | version: "1.16.0" 46 | convert: 47 | dependency: transitive 48 | description: 49 | name: convert 50 | url: "https://pub.dartlang.org" 51 | source: hosted 52 | version: "3.0.2" 53 | coverage: 54 | dependency: transitive 55 | description: 56 | name: coverage 57 | url: "https://pub.dartlang.org" 58 | source: hosted 59 | version: "1.6.0" 60 | crypto: 61 | dependency: transitive 62 | description: 63 | name: crypto 64 | url: "https://pub.dartlang.org" 65 | source: hosted 66 | version: "3.0.2" 67 | file: 68 | dependency: transitive 69 | description: 70 | name: file 71 | url: "https://pub.dartlang.org" 72 | source: hosted 73 | version: "6.1.4" 74 | frontend_server_client: 75 | dependency: transitive 76 | description: 77 | name: frontend_server_client 78 | url: "https://pub.dartlang.org" 79 | source: hosted 80 | version: "3.0.0" 81 | glob: 82 | dependency: transitive 83 | description: 84 | name: glob 85 | url: "https://pub.dartlang.org" 86 | source: hosted 87 | version: "2.1.0" 88 | http_multi_server: 89 | dependency: transitive 90 | description: 91 | name: http_multi_server 92 | url: "https://pub.dartlang.org" 93 | source: hosted 94 | version: "3.2.1" 95 | http_parser: 96 | dependency: transitive 97 | description: 98 | name: http_parser 99 | url: "https://pub.dartlang.org" 100 | source: hosted 101 | version: "4.0.1" 102 | io: 103 | dependency: transitive 104 | description: 105 | name: io 106 | url: "https://pub.dartlang.org" 107 | source: hosted 108 | version: "1.0.3" 109 | js: 110 | dependency: transitive 111 | description: 112 | name: js 113 | url: "https://pub.dartlang.org" 114 | source: hosted 115 | version: "0.6.4" 116 | lints: 117 | dependency: "direct dev" 118 | description: 119 | name: lints 120 | url: "https://pub.dartlang.org" 121 | source: hosted 122 | version: "2.0.0" 123 | logging: 124 | dependency: transitive 125 | description: 126 | name: logging 127 | url: "https://pub.dartlang.org" 128 | source: hosted 129 | version: "1.0.2" 130 | matcher: 131 | dependency: transitive 132 | description: 133 | name: matcher 134 | url: "https://pub.dartlang.org" 135 | source: hosted 136 | version: "0.12.12" 137 | meta: 138 | dependency: transitive 139 | description: 140 | name: meta 141 | url: "https://pub.dartlang.org" 142 | source: hosted 143 | version: "1.8.0" 144 | mime: 145 | dependency: transitive 146 | description: 147 | name: mime 148 | url: "https://pub.dartlang.org" 149 | source: hosted 150 | version: "1.0.2" 151 | node_preamble: 152 | dependency: transitive 153 | description: 154 | name: node_preamble 155 | url: "https://pub.dartlang.org" 156 | source: hosted 157 | version: "2.0.1" 158 | package_config: 159 | dependency: transitive 160 | description: 161 | name: package_config 162 | url: "https://pub.dartlang.org" 163 | source: hosted 164 | version: "2.1.0" 165 | path: 166 | dependency: transitive 167 | description: 168 | name: path 169 | url: "https://pub.dartlang.org" 170 | source: hosted 171 | version: "1.8.2" 172 | pool: 173 | dependency: transitive 174 | description: 175 | name: pool 176 | url: "https://pub.dartlang.org" 177 | source: hosted 178 | version: "1.5.1" 179 | pub_semver: 180 | dependency: transitive 181 | description: 182 | name: pub_semver 183 | url: "https://pub.dartlang.org" 184 | source: hosted 185 | version: "2.1.1" 186 | shelf: 187 | dependency: transitive 188 | description: 189 | name: shelf 190 | url: "https://pub.dartlang.org" 191 | source: hosted 192 | version: "1.3.2" 193 | shelf_packages_handler: 194 | dependency: transitive 195 | description: 196 | name: shelf_packages_handler 197 | url: "https://pub.dartlang.org" 198 | source: hosted 199 | version: "3.0.1" 200 | shelf_static: 201 | dependency: transitive 202 | description: 203 | name: shelf_static 204 | url: "https://pub.dartlang.org" 205 | source: hosted 206 | version: "1.1.1" 207 | shelf_web_socket: 208 | dependency: transitive 209 | description: 210 | name: shelf_web_socket 211 | url: "https://pub.dartlang.org" 212 | source: hosted 213 | version: "1.0.2" 214 | source_map_stack_trace: 215 | dependency: transitive 216 | description: 217 | name: source_map_stack_trace 218 | url: "https://pub.dartlang.org" 219 | source: hosted 220 | version: "2.1.0" 221 | source_maps: 222 | dependency: transitive 223 | description: 224 | name: source_maps 225 | url: "https://pub.dartlang.org" 226 | source: hosted 227 | version: "0.10.10" 228 | source_span: 229 | dependency: transitive 230 | description: 231 | name: source_span 232 | url: "https://pub.dartlang.org" 233 | source: hosted 234 | version: "1.9.1" 235 | stack_trace: 236 | dependency: transitive 237 | description: 238 | name: stack_trace 239 | url: "https://pub.dartlang.org" 240 | source: hosted 241 | version: "1.10.0" 242 | stream_channel: 243 | dependency: transitive 244 | description: 245 | name: stream_channel 246 | url: "https://pub.dartlang.org" 247 | source: hosted 248 | version: "2.1.0" 249 | string_scanner: 250 | dependency: transitive 251 | description: 252 | name: string_scanner 253 | url: "https://pub.dartlang.org" 254 | source: hosted 255 | version: "1.1.1" 256 | term_glyph: 257 | dependency: transitive 258 | description: 259 | name: term_glyph 260 | url: "https://pub.dartlang.org" 261 | source: hosted 262 | version: "1.2.1" 263 | test: 264 | dependency: "direct dev" 265 | description: 266 | name: test 267 | url: "https://pub.dartlang.org" 268 | source: hosted 269 | version: "1.21.6" 270 | test_api: 271 | dependency: transitive 272 | description: 273 | name: test_api 274 | url: "https://pub.dartlang.org" 275 | source: hosted 276 | version: "0.4.14" 277 | test_core: 278 | dependency: transitive 279 | description: 280 | name: test_core 281 | url: "https://pub.dartlang.org" 282 | source: hosted 283 | version: "0.4.18" 284 | typed_data: 285 | dependency: transitive 286 | description: 287 | name: typed_data 288 | url: "https://pub.dartlang.org" 289 | source: hosted 290 | version: "1.3.1" 291 | vm_service: 292 | dependency: transitive 293 | description: 294 | name: vm_service 295 | url: "https://pub.dartlang.org" 296 | source: hosted 297 | version: "9.4.0" 298 | watcher: 299 | dependency: transitive 300 | description: 301 | name: watcher 302 | url: "https://pub.dartlang.org" 303 | source: hosted 304 | version: "1.0.1" 305 | web_socket_channel: 306 | dependency: transitive 307 | description: 308 | name: web_socket_channel 309 | url: "https://pub.dartlang.org" 310 | source: hosted 311 | version: "2.2.0" 312 | webkit_inspection_protocol: 313 | dependency: transitive 314 | description: 315 | name: webkit_inspection_protocol 316 | url: "https://pub.dartlang.org" 317 | source: hosted 318 | version: "1.2.0" 319 | yaml: 320 | dependency: transitive 321 | description: 322 | name: yaml 323 | url: "https://pub.dartlang.org" 324 | source: hosted 325 | version: "3.1.1" 326 | sdks: 327 | dart: ">=2.18.0 <3.0.0" 328 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: design_patterns_dart 2 | description: A sample command-line application. 3 | version: 1.0.0 4 | # homepage: https://www.example.com 5 | 6 | environment: 7 | sdk: '>=2.18.0 <3.0.0' 8 | 9 | # dependencies: 10 | # path: ^1.8.0 11 | 12 | dev_dependencies: 13 | lints: ^2.0.0 14 | test: ^1.16.0 15 | -------------------------------------------------------------------------------- /test/design_patterns_dart_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:design_patterns_dart/design_patterns_dart.dart'; 2 | import 'package:test/test.dart'; 3 | 4 | void main() { 5 | test('calculate', () { 6 | expect(calculate(), 42); 7 | }); 8 | } 9 | --------------------------------------------------------------------------------