SlideShare a Scribd company logo
1 of 28
By SmartBoard Team
Agenda
 Scenario & Writing UML
 Discuss with each team’s UML
 What if…
 BMVV design
 Strategy pattern
 Applied with BMVV design
 More exercise..
Scenario
   Act yourself as Car company owner




   Car component will consist of
     Engine Type

     Fuel used

     Nitrous (Additional boost)
Scenario (2)
  From its components, we can calculate
the fuel burn rate. So, it should include method
   getBurnFuel(double distance).
    It comes from Engines power + Nitrous power (if used)

   Each car can used only
       One type of engine
       One type of Fuel
       One type of Nitrous


  You need some program to
show fuel burn rate for each car

   Car components can be changed in the future.

   Every team, please write UML Class diagram to
    according to the requirement above…
Writing UML ~10-15 min



  Take your time…
Time’s up….
   Let’s see your UML diagram
What if..
 More engine type is added
 More fuel type is added
 More nitrous type is added
 Some car can’t use some engine
 No more benzene ??


   Can you design support this changes?
Let’s record your problem
BMVV Car company design
B

    cd Car


                                        Car

                         #   engine: String
                         #   fuel: String
                         #   boost: String
                         -   accel: double

                         +   setBoost(String) : void
                         +   setEngine(String) : void
                         +   BurnFuel(double) : double
                         +   getFuelName() : String
                         +   getEngineName() : String
                         +   getBoostName() : String
                         #   getBurnFuel(double) : double
                         +   performBoost(double) : double




             JazzCar                                             TankCar
                                     PorcheCar
       +     JazzCar()                                       +   TankCar()
                                 +   PorcheCar()
BMVV Car company design #2
  B
                                                                         protected double getBurnFuel(double distance)
                                                                         {
                                                                         if(engine.equalsIgnoreCase("1500CC")
cd Car                                                                   && fuel.equalsIgnoreCase("Benzene"))
                                                                         {
                                    Car                                       double consume = distance*0.054;
                                                                              consume = consume*18/17;
                     #   engine: String                                       return consume;
                     #   fuel: String                                    }
                     #   boost: String                                   else if(engine.equalsIgnoreCase("1500CC")
                     -   accel: double
                                                                         && fuel.equalsIgnoreCase("Diesel"))
                                                                         { ………….. }
                     +   setBoost(String) : void
                                                                         else if(engine.equalsIgnoreCase("1500CC")
                     +   setEngine(String) : void
                                                                          && fuel.equalsIgnoreCase("Gasohol"))
                     +   BurnFuel(double) : double
                     +   getFuelName() : String
                                                                         { …………..         }
                     +   getEngineName() : String                        else if(engine.equalsIgnoreCase("1900CC")
                     +   getBoostName() : String                             && fuel.equalsIgnoreCase("Benzene"))
                     #   getBurnFuel(double) : double                    { …….        }
                     +   performBoost(double) : double                   …………..
                                                                         …….
                                                                         …


         JazzCar                                             TankCar
                                 PorcheCar
   +     JazzCar()                                       +   TankCar()
                             +   PorcheCar()
Problems occurs when…
   If 4500cc engine are added
 No more benzene used.
 Super Gasohol is invented.

    If each case has more
 else if(engine.equalsIgnoreCase(“4500CC”)
  && fuel.equalsIgnoreCase(“Benzene”))
  { conditions….
 else if(engine.equalsIgnoreCase(“1500CC”)
 && fuel.equalsIgnoreCase(“SuperGasohol”))
   }
 { …… if(engine.equalsIgnoreCase(“4500CC”)
   else }
   && fuel.equalsIgnoreCase(“Diesel”))
   {

    else if(engine.equalsIgnoreCase(“1900CC”)
      }
    && fuel.equalsIgnoreCase(“SuperGasohol”))
      else if(engine.equalsIgnoreCase(“4500CC”)
    { && …Another fuel type… )
       …… }
      .
      .
      .
      else if(engine.equalsIgnoreCase(“4500CC”)
      && fuel.equalsIgnoreCase(“SuperGasohol”))
      { …… }
Unable to encapsulates data
   According to this design, if you company
    need to outsource your work…


                   Con
                         fide
                              ntia
                                   l
                      $   $ $$$
Strategy patterns
   Define a family of algorithms, encapsulate, and
    make them interchangeable. Strategy lets the
    algorithm vary independently from clients that
    use it.




               http://en.wikipedia.org/wiki/Strategy_pattern
Thai military communication
 network

                          Every message will be
                               encrypted.




Communication between
 a station and an unite
Old cipher machine model
                   Break encapsulation rule
    (RTA,2)
                   Conditions
                   2. decryptA
    Machine        3. decryptB
                   4. decryptC
                   5. None
     SUB
                       1500 lines
New cipher machine model
                              Alternative
                               subclass

                                            <interface>
    (RTA, object)
      Object.decrypt(“RTA”)

                                             decryptB

        Machine                              decryptA
Eliminate
conditions               Family of
                                               A choice of
                        algorithms           implementation
          SUB                                  None
                                                   s
New cipher machine model
 Decrypt A and B can use signature only a
  string. Object.decrypt(String);
 But Decrypt C need more parameters.
  Object.decrypt(String, int);
             Communication
 So method signature should have two
               overhead
  parameters. Object.decrypt(String, int);
 Ex . ObjectA.decrypt(“RTA”, Null);
      ObjectB.decrypt(“RTA”, Null);
  ObjectC.decrypt(“RTA”, 366);
Consequences
 Families of related algorithms.
 An alternative to subclassing.
 Strategies eliminate conditional statements.
 A choice of implementations.
 Clients must be aware of different
  strategies.
 Communication overhead between Strategy
  and Context.
 Increased number of objects.
Another example : Sort
    Assume that, you need to write a sort program
    There’re many kinds of sort..
    Strategy is what we group the many algorithms
     that do the same things and make it
     interchangeable at run-time
                           Ascending
        Bubble                Sort
           Runtime
         Sort                             SortStrategies
                     Selection
Descending             Sort
   Sort
                                 Input       Result
             Quick                 Heap
                                  #2
                                  #1          #2
                                              #1
              Sort                Sort
Another example : Sort #2
        Change the algorithm
            at runtime
Apply strategy with BMVV design
           Indicates the problem..
            I
cd Car


                                    Car

                     #   engine: String
                     #   fuel: String


                                                                                          ntain
                     #   boost: String


                                                                                      mai
                     -   accel: double



                                                                              rd to
                     +   setBoost(String) : void
                     +
                     +
                     +
                         setEngine(String) : void
                         BurnFuel(double) : double
                         getFuelName() : String
                                                                           Ha
                     +   getEngineName() : String
                     +   getBoostName() : String
                     #   getBurnFuel(double) : double
                     +   performBoost(double) : double




         JazzCar                                             TankCar
                                 PorcheCar
   +     JazzCar()                                       +   TankCar()
                             +   PorcheCar()                             Move it to the new class…
Apply strategy with BMVV design
          Need getBurnFuel()      So as Nitrous
   Re-designing
          from different factor
Apply strategy with BMVV design                               Engine4500ccBenzene                                 Engine4500ccGasohol                             Engine4500ccDiesel
   Overall design
    O
                                                                       If 4500cc engine is added?
    cd carPattern


            Engine1500CCBenzene

       +    getBurnFuel (double) : doubl e                 Engine1900CCBenzene                                Engine1900CCDiesel                      Engine1900CCGasohol
       +    getEngi neName() : Stri ng
       +    getFuel Name() : Stri ng               +       getBurnFuel (doubl e) : doubl e           +      getBurnFuel(doubl e) : doubl e        +   getBurnFuel (doubl e) : doubl e
                                                   +       getEngi neName() : Stri ng                +      getEngi neName() : Stri ng            +   getEngi neName() : Stri ng
                                                   +       getFuel Name() : Stri ng                  +      getFuelName() : Stri ng               +   getFuel Name() : Stri ng
              Engine1500CCDiesel

        +   getBurnFuel (doubl e) : double
                                                                                                                                                                NoBoost
        +   getEngi neName() : Stri ng
        +   getFuel Name() : Stri ng
                                                                                                                                                  +   getBurnFuel (doubl e) : doubl e
                                                                                                                                                  +   getFuel Name() : Stri ng
                                                                «i nterface»                                       «i nterface»



            Easier w
             Engine1500CCGasohol                                   Engine                                              Nitrous
                                                                                                                                                            NitrousGasohol



                                              hen doin
                                               +       getBurnFuel (doubl e) : double               +       getBurnFuel (doubl e) : doubl e
        +   getBurnFuel (doubl e) : doubl e                                                         +       getFuel Name() : Stri ng
                                               +       getEngi neName() : Stri ng
        +   getEngi neName() : String                                                                                                             +   getBurnFuel (doubl e) : doubl e



                                                                                          g th e ma
                                               +       getFuel Name() : Stri ng
        +   getFuel Name() : Stri ng                                                                                                              +   getFuel Name() : Stri ng




                                                                                                                                    intenanc
                                                                 #engi ne                                #Boost
                                                                                                                                                             NitrousDiesel
             Engine2500CCBenzene

       +
       +
       +
            getBurnFuel (doubl e) : doubl e
            getEngi neName() : Stri ng
            getFuel Name() : Stri ng                                  #
                                                                      #
                                                                              Boost: Ni trous
                                                                              engi ne: Engi ne
                                                                                              Car
                                                                                                                                                  +
                                                                                                                                                  +
                                                                                                                                                                             e !!!
                                                                                                                                                      getBurnFuel (doubl e) : doubl e
                                                                                                                                                      getFuel Name() : Stri ng


                                                                                                                                                            NitrousBenzene
                                                                      -       Accel : doubl e
             Engine2500CCGasohol                                                                                                                  +   getBurnFuel (doubl e) : doubl e
                                                                      +       performBoost(doubl e) : doubl e
                                                                                                                                                  +   getFuel Name() : Stri ng
        +   getBurnFuel (doubl e) : double                            +       «property set» setBoost(Ni trous) : voi d
        +   getEngi neName() : Stri ng                                +       setEngi ne(Engi ne) : voi d
        +   getFuel Name() : Stri ng                                  +       BurnFuel (doubl e) : doubl e
                                                                      +       Run() : voi d
                                                                      +       Fuel () : voi d
                                                                                                                                                          Garage
              Engine2500CCDiesel
                                                                                                                                              +   mai n(Stri ng[]) : voi d
        +   getBurnFuel (doubl e) : doubl e                  JazzCar                       TankCar                      PorcheCar
        +   getEngi neName() : String
        +   getFuel Name() : Stri ng                   +    JazzCar()                 +   T ankCar()               +    PorcheCar()
                                                       +    Fuel () : voi d           +   Fuel () : voi d          +    Fuel() : voi d




                                                                                                     If no more benzene?
Apply strategy with BMVV design
     How it works at runtime
                          It will call BurnFuel(double)
                             according to its engine




Jazz is changing its
       engine
An action adventure game
Solutions of exercise
Q/A
References
   www.viewimages.com
   www.thailandstrategy.com
   http://www.maxituning.pl/archiwum/0412/pics/technik
    a/nos2.jpg
   www.mysticcobra.net/system/
   http://jpfamily.net/Coolpix/NHRA/slides/
   http://www.robinstewart.com/products/graphics/gs_ic
    on.gif
   www.freewarebox.com/screenshot_2476_clock.html
   http://tv.pcworld.hu/apix/0612/Data%20thief.png
   http://www.offthemarkcartoons.com/cartoons/

More Related Content

What's hot

Basic c++ programs
Basic c++ programsBasic c++ programs
Basic c++ programsharman kaur
 
What&rsquo;s new in Visual C++
What&rsquo;s new in Visual C++What&rsquo;s new in Visual C++
What&rsquo;s new in Visual C++Microsoft
 
Lesson 18: Maximum and Minimum Vaues
Lesson 18: Maximum and Minimum VauesLesson 18: Maximum and Minimum Vaues
Lesson 18: Maximum and Minimum VauesMatthew Leingang
 
Lesson 18: Maximum and Minimum Vaues
Lesson 18: Maximum and Minimum VauesLesson 18: Maximum and Minimum Vaues
Lesson 18: Maximum and Minimum VauesMatthew Leingang
 
CUDA by Example : Parallel Programming in CUDA C : Notes
CUDA by Example : Parallel Programming in CUDA C : NotesCUDA by Example : Parallel Programming in CUDA C : Notes
CUDA by Example : Parallel Programming in CUDA C : NotesSubhajit Sahu
 
Killing Bugs with Pry
Killing Bugs with PryKilling Bugs with Pry
Killing Bugs with PryJason Carter
 
CUDA by Example : Introduction to CUDA C : Notes
CUDA by Example : Introduction to CUDA C : NotesCUDA by Example : Introduction to CUDA C : Notes
CUDA by Example : Introduction to CUDA C : NotesSubhajit Sahu
 
Boost.Python: C++ and Python Integration
Boost.Python: C++ and Python IntegrationBoost.Python: C++ and Python Integration
Boost.Python: C++ and Python IntegrationGlobalLogic Ukraine
 
PyTorch crash course
PyTorch crash coursePyTorch crash course
PyTorch crash courseNader Karimi
 
Introduction to PyTorch
Introduction to PyTorchIntroduction to PyTorch
Introduction to PyTorchJun Young Park
 

What's hot (12)

Basic c++ programs
Basic c++ programsBasic c++ programs
Basic c++ programs
 
What&rsquo;s new in Visual C++
What&rsquo;s new in Visual C++What&rsquo;s new in Visual C++
What&rsquo;s new in Visual C++
 
Advanced cocos2d
Advanced cocos2dAdvanced cocos2d
Advanced cocos2d
 
Lesson 18: Maximum and Minimum Vaues
Lesson 18: Maximum and Minimum VauesLesson 18: Maximum and Minimum Vaues
Lesson 18: Maximum and Minimum Vaues
 
Lesson 18: Maximum and Minimum Vaues
Lesson 18: Maximum and Minimum VauesLesson 18: Maximum and Minimum Vaues
Lesson 18: Maximum and Minimum Vaues
 
CUDA by Example : Parallel Programming in CUDA C : Notes
CUDA by Example : Parallel Programming in CUDA C : NotesCUDA by Example : Parallel Programming in CUDA C : Notes
CUDA by Example : Parallel Programming in CUDA C : Notes
 
Killing Bugs with Pry
Killing Bugs with PryKilling Bugs with Pry
Killing Bugs with Pry
 
CUDA by Example : Introduction to CUDA C : Notes
CUDA by Example : Introduction to CUDA C : NotesCUDA by Example : Introduction to CUDA C : Notes
CUDA by Example : Introduction to CUDA C : Notes
 
Brief Introduction to Cython
Brief Introduction to CythonBrief Introduction to Cython
Brief Introduction to Cython
 
Boost.Python: C++ and Python Integration
Boost.Python: C++ and Python IntegrationBoost.Python: C++ and Python Integration
Boost.Python: C++ and Python Integration
 
PyTorch crash course
PyTorch crash coursePyTorch crash course
PyTorch crash course
 
Introduction to PyTorch
Introduction to PyTorchIntroduction to PyTorch
Introduction to PyTorch
 

Viewers also liked

Viewers also liked (12)

Design pattern strategy pattern 策略模式
Design pattern strategy pattern 策略模式Design pattern strategy pattern 策略模式
Design pattern strategy pattern 策略模式
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Design patterns
Design patternsDesign patterns
Design patterns
 
10 strategy pattern
10 strategy pattern10 strategy pattern
10 strategy pattern
 
Introduction to Design Patterns
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design Patterns
 
Design patterns - Strategy Pattern
Design patterns - Strategy PatternDesign patterns - Strategy Pattern
Design patterns - Strategy Pattern
 
Strategy Pattern
Strategy PatternStrategy Pattern
Strategy Pattern
 
Design Pattern in Software Engineering
Design Pattern in Software EngineeringDesign Pattern in Software Engineering
Design Pattern in Software Engineering
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Strategy Design Pattern
Strategy Design PatternStrategy Design Pattern
Strategy Design Pattern
 
Strategy and Template Pattern
Strategy and Template PatternStrategy and Template Pattern
Strategy and Template Pattern
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns ppt
 

Similar to Ku bangkok sw-eng-dp-02_smart_board_strategypattern

Scala Self Types by Gregor Heine, Principal Software Engineer at Gilt
Scala Self Types by Gregor Heine, Principal Software Engineer at GiltScala Self Types by Gregor Heine, Principal Software Engineer at Gilt
Scala Self Types by Gregor Heine, Principal Software Engineer at GiltGilt Tech Talks
 
12 Monkeys Inside JS Engine
12 Monkeys Inside JS Engine12 Monkeys Inside JS Engine
12 Monkeys Inside JS EngineChengHui Weng
 
(9) cpp abstractions separated_compilation_and_binding_part_ii
(9) cpp abstractions separated_compilation_and_binding_part_ii(9) cpp abstractions separated_compilation_and_binding_part_ii
(9) cpp abstractions separated_compilation_and_binding_part_iiNico Ludwig
 
Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...
Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...
Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...PVS-Studio
 
How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...Codemotion
 
Designing REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDesigning REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDmitriy Sobko
 
JVM performance options. How it works
JVM performance options. How it worksJVM performance options. How it works
JVM performance options. How it worksDmitriy Dumanskiy
 
For the following questions, you will implement the data structure to.pdf
For the following questions, you will implement the data structure to.pdfFor the following questions, you will implement the data structure to.pdf
For the following questions, you will implement the data structure to.pdfarjunhassan8
 
(7) cpp abstractions inheritance_part_ii
(7) cpp abstractions inheritance_part_ii(7) cpp abstractions inheritance_part_ii
(7) cpp abstractions inheritance_part_iiNico Ludwig
 
Create docker image with bluemix dev ops
Create docker image with bluemix dev opsCreate docker image with bluemix dev ops
Create docker image with bluemix dev opsJoseph Chang
 
BOS K8S Meetup - Finetuning LLama 2 Model on GKE.pdf
BOS K8S Meetup - Finetuning LLama 2 Model on GKE.pdfBOS K8S Meetup - Finetuning LLama 2 Model on GKE.pdf
BOS K8S Meetup - Finetuning LLama 2 Model on GKE.pdfMichaelOLeary82
 
Config interface
Config interfaceConfig interface
Config interfaceRyan Boland
 
The C# programming laguage delegates notes Delegates.pptx
The C# programming laguage delegates notes Delegates.pptxThe C# programming laguage delegates notes Delegates.pptx
The C# programming laguage delegates notes Delegates.pptxVitsRangannavar
 
Distributed Model Training using MXNet with Horovod
Distributed Model Training using MXNet with HorovodDistributed Model Training using MXNet with Horovod
Distributed Model Training using MXNet with HorovodLin Yuan
 
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docxeugeniadean34240
 
#include iostream#include string#include iomanip#inclu.docx
#include iostream#include string#include iomanip#inclu.docx#include iostream#include string#include iomanip#inclu.docx
#include iostream#include string#include iomanip#inclu.docxmayank272369
 
Eclipse Code Recommenders @ MAJUG 2011
Eclipse Code Recommenders @ MAJUG 2011Eclipse Code Recommenders @ MAJUG 2011
Eclipse Code Recommenders @ MAJUG 2011Marcel Bruch
 
From android/ java to swift (2)
From android/ java to swift (2)From android/ java to swift (2)
From android/ java to swift (2)allanh0526
 
Reactive Access to MongoDB from Scala
Reactive Access to MongoDB from ScalaReactive Access to MongoDB from Scala
Reactive Access to MongoDB from ScalaHermann Hueck
 

Similar to Ku bangkok sw-eng-dp-02_smart_board_strategypattern (20)

Scala Self Types by Gregor Heine, Principal Software Engineer at Gilt
Scala Self Types by Gregor Heine, Principal Software Engineer at GiltScala Self Types by Gregor Heine, Principal Software Engineer at Gilt
Scala Self Types by Gregor Heine, Principal Software Engineer at Gilt
 
12 Monkeys Inside JS Engine
12 Monkeys Inside JS Engine12 Monkeys Inside JS Engine
12 Monkeys Inside JS Engine
 
(9) cpp abstractions separated_compilation_and_binding_part_ii
(9) cpp abstractions separated_compilation_and_binding_part_ii(9) cpp abstractions separated_compilation_and_binding_part_ii
(9) cpp abstractions separated_compilation_and_binding_part_ii
 
Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...
Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...
Serious Sam shooter anniversary - finding bugs in the code of the Serious Eng...
 
How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...
 
Designing REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDesigning REST API automation tests in Kotlin
Designing REST API automation tests in Kotlin
 
JVM performance options. How it works
JVM performance options. How it worksJVM performance options. How it works
JVM performance options. How it works
 
For the following questions, you will implement the data structure to.pdf
For the following questions, you will implement the data structure to.pdfFor the following questions, you will implement the data structure to.pdf
For the following questions, you will implement the data structure to.pdf
 
(7) cpp abstractions inheritance_part_ii
(7) cpp abstractions inheritance_part_ii(7) cpp abstractions inheritance_part_ii
(7) cpp abstractions inheritance_part_ii
 
Create docker image with bluemix dev ops
Create docker image with bluemix dev opsCreate docker image with bluemix dev ops
Create docker image with bluemix dev ops
 
Unit4_2.pdf
Unit4_2.pdfUnit4_2.pdf
Unit4_2.pdf
 
BOS K8S Meetup - Finetuning LLama 2 Model on GKE.pdf
BOS K8S Meetup - Finetuning LLama 2 Model on GKE.pdfBOS K8S Meetup - Finetuning LLama 2 Model on GKE.pdf
BOS K8S Meetup - Finetuning LLama 2 Model on GKE.pdf
 
Config interface
Config interfaceConfig interface
Config interface
 
The C# programming laguage delegates notes Delegates.pptx
The C# programming laguage delegates notes Delegates.pptxThe C# programming laguage delegates notes Delegates.pptx
The C# programming laguage delegates notes Delegates.pptx
 
Distributed Model Training using MXNet with Horovod
Distributed Model Training using MXNet with HorovodDistributed Model Training using MXNet with Horovod
Distributed Model Training using MXNet with Horovod
 
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
 
#include iostream#include string#include iomanip#inclu.docx
#include iostream#include string#include iomanip#inclu.docx#include iostream#include string#include iomanip#inclu.docx
#include iostream#include string#include iomanip#inclu.docx
 
Eclipse Code Recommenders @ MAJUG 2011
Eclipse Code Recommenders @ MAJUG 2011Eclipse Code Recommenders @ MAJUG 2011
Eclipse Code Recommenders @ MAJUG 2011
 
From android/ java to swift (2)
From android/ java to swift (2)From android/ java to swift (2)
From android/ java to swift (2)
 
Reactive Access to MongoDB from Scala
Reactive Access to MongoDB from ScalaReactive Access to MongoDB from Scala
Reactive Access to MongoDB from Scala
 

Recently uploaded

Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 

Recently uploaded (20)

Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 

Ku bangkok sw-eng-dp-02_smart_board_strategypattern

  • 2. Agenda  Scenario & Writing UML  Discuss with each team’s UML  What if…  BMVV design  Strategy pattern  Applied with BMVV design  More exercise..
  • 3. Scenario  Act yourself as Car company owner  Car component will consist of  Engine Type  Fuel used  Nitrous (Additional boost)
  • 4. Scenario (2)  From its components, we can calculate the fuel burn rate. So, it should include method getBurnFuel(double distance). It comes from Engines power + Nitrous power (if used)  Each car can used only  One type of engine  One type of Fuel  One type of Nitrous  You need some program to show fuel burn rate for each car  Car components can be changed in the future.  Every team, please write UML Class diagram to according to the requirement above…
  • 5. Writing UML ~10-15 min Take your time…
  • 6. Time’s up….  Let’s see your UML diagram
  • 7. What if..  More engine type is added  More fuel type is added  More nitrous type is added  Some car can’t use some engine  No more benzene ??  Can you design support this changes?
  • 9. BMVV Car company design B cd Car Car # engine: String # fuel: String # boost: String - accel: double + setBoost(String) : void + setEngine(String) : void + BurnFuel(double) : double + getFuelName() : String + getEngineName() : String + getBoostName() : String # getBurnFuel(double) : double + performBoost(double) : double JazzCar TankCar PorcheCar + JazzCar() + TankCar() + PorcheCar()
  • 10. BMVV Car company design #2 B protected double getBurnFuel(double distance) { if(engine.equalsIgnoreCase("1500CC") cd Car && fuel.equalsIgnoreCase("Benzene")) { Car double consume = distance*0.054; consume = consume*18/17; # engine: String return consume; # fuel: String } # boost: String else if(engine.equalsIgnoreCase("1500CC") - accel: double && fuel.equalsIgnoreCase("Diesel")) { ………….. } + setBoost(String) : void else if(engine.equalsIgnoreCase("1500CC") + setEngine(String) : void && fuel.equalsIgnoreCase("Gasohol")) + BurnFuel(double) : double + getFuelName() : String { ………….. } + getEngineName() : String else if(engine.equalsIgnoreCase("1900CC") + getBoostName() : String && fuel.equalsIgnoreCase("Benzene")) # getBurnFuel(double) : double { ……. } + performBoost(double) : double ………….. ……. … JazzCar TankCar PorcheCar + JazzCar() + TankCar() + PorcheCar()
  • 11. Problems occurs when…  If 4500cc engine are added  No more benzene used.  Super Gasohol is invented. If each case has more  else if(engine.equalsIgnoreCase(“4500CC”) && fuel.equalsIgnoreCase(“Benzene”)) { conditions…. else if(engine.equalsIgnoreCase(“1500CC”) && fuel.equalsIgnoreCase(“SuperGasohol”)) } { …… if(engine.equalsIgnoreCase(“4500CC”) else } && fuel.equalsIgnoreCase(“Diesel”)) { else if(engine.equalsIgnoreCase(“1900CC”) } && fuel.equalsIgnoreCase(“SuperGasohol”)) else if(engine.equalsIgnoreCase(“4500CC”) { && …Another fuel type… ) …… } . . . else if(engine.equalsIgnoreCase(“4500CC”) && fuel.equalsIgnoreCase(“SuperGasohol”)) { …… }
  • 12. Unable to encapsulates data  According to this design, if you company need to outsource your work… Con fide ntia l $ $ $$$
  • 13. Strategy patterns  Define a family of algorithms, encapsulate, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it. http://en.wikipedia.org/wiki/Strategy_pattern
  • 14. Thai military communication network Every message will be encrypted. Communication between a station and an unite
  • 15. Old cipher machine model Break encapsulation rule (RTA,2) Conditions 2. decryptA Machine 3. decryptB 4. decryptC 5. None SUB 1500 lines
  • 16. New cipher machine model Alternative subclass <interface> (RTA, object) Object.decrypt(“RTA”) decryptB Machine decryptA Eliminate conditions Family of A choice of algorithms implementation SUB None s
  • 17. New cipher machine model  Decrypt A and B can use signature only a string. Object.decrypt(String);  But Decrypt C need more parameters. Object.decrypt(String, int); Communication  So method signature should have two overhead parameters. Object.decrypt(String, int);  Ex . ObjectA.decrypt(“RTA”, Null); ObjectB.decrypt(“RTA”, Null); ObjectC.decrypt(“RTA”, 366);
  • 18. Consequences  Families of related algorithms.  An alternative to subclassing.  Strategies eliminate conditional statements.  A choice of implementations.  Clients must be aware of different strategies.  Communication overhead between Strategy and Context.  Increased number of objects.
  • 19. Another example : Sort  Assume that, you need to write a sort program  There’re many kinds of sort..  Strategy is what we group the many algorithms that do the same things and make it interchangeable at run-time Ascending Bubble Sort Runtime Sort SortStrategies Selection Descending Sort Sort Input Result Quick Heap #2 #1 #2 #1 Sort Sort
  • 20. Another example : Sort #2 Change the algorithm at runtime
  • 21. Apply strategy with BMVV design  Indicates the problem.. I cd Car Car # engine: String # fuel: String ntain # boost: String mai - accel: double rd to + setBoost(String) : void + + + setEngine(String) : void BurnFuel(double) : double getFuelName() : String Ha + getEngineName() : String + getBoostName() : String # getBurnFuel(double) : double + performBoost(double) : double JazzCar TankCar PorcheCar + JazzCar() + TankCar() + PorcheCar() Move it to the new class…
  • 22. Apply strategy with BMVV design Need getBurnFuel() So as Nitrous  Re-designing from different factor
  • 23. Apply strategy with BMVV design Engine4500ccBenzene Engine4500ccGasohol Engine4500ccDiesel  Overall design O If 4500cc engine is added? cd carPattern Engine1500CCBenzene + getBurnFuel (double) : doubl e Engine1900CCBenzene Engine1900CCDiesel Engine1900CCGasohol + getEngi neName() : Stri ng + getFuel Name() : Stri ng + getBurnFuel (doubl e) : doubl e + getBurnFuel(doubl e) : doubl e + getBurnFuel (doubl e) : doubl e + getEngi neName() : Stri ng + getEngi neName() : Stri ng + getEngi neName() : Stri ng + getFuel Name() : Stri ng + getFuelName() : Stri ng + getFuel Name() : Stri ng Engine1500CCDiesel + getBurnFuel (doubl e) : double NoBoost + getEngi neName() : Stri ng + getFuel Name() : Stri ng + getBurnFuel (doubl e) : doubl e + getFuel Name() : Stri ng «i nterface» «i nterface» Easier w Engine1500CCGasohol Engine Nitrous NitrousGasohol hen doin + getBurnFuel (doubl e) : double + getBurnFuel (doubl e) : doubl e + getBurnFuel (doubl e) : doubl e + getFuel Name() : Stri ng + getEngi neName() : Stri ng + getEngi neName() : String + getBurnFuel (doubl e) : doubl e g th e ma + getFuel Name() : Stri ng + getFuel Name() : Stri ng + getFuel Name() : Stri ng intenanc #engi ne #Boost NitrousDiesel Engine2500CCBenzene + + + getBurnFuel (doubl e) : doubl e getEngi neName() : Stri ng getFuel Name() : Stri ng # # Boost: Ni trous engi ne: Engi ne Car + + e !!! getBurnFuel (doubl e) : doubl e getFuel Name() : Stri ng NitrousBenzene - Accel : doubl e Engine2500CCGasohol + getBurnFuel (doubl e) : doubl e + performBoost(doubl e) : doubl e + getFuel Name() : Stri ng + getBurnFuel (doubl e) : double + «property set» setBoost(Ni trous) : voi d + getEngi neName() : Stri ng + setEngi ne(Engi ne) : voi d + getFuel Name() : Stri ng + BurnFuel (doubl e) : doubl e + Run() : voi d + Fuel () : voi d Garage Engine2500CCDiesel + mai n(Stri ng[]) : voi d + getBurnFuel (doubl e) : doubl e JazzCar TankCar PorcheCar + getEngi neName() : String + getFuel Name() : Stri ng + JazzCar() + T ankCar() + PorcheCar() + Fuel () : voi d + Fuel () : voi d + Fuel() : voi d If no more benzene?
  • 24. Apply strategy with BMVV design  How it works at runtime It will call BurnFuel(double) according to its engine Jazz is changing its engine
  • 27. Q/A
  • 28. References  www.viewimages.com  www.thailandstrategy.com  http://www.maxituning.pl/archiwum/0412/pics/technik a/nos2.jpg  www.mysticcobra.net/system/  http://jpfamily.net/Coolpix/NHRA/slides/  http://www.robinstewart.com/products/graphics/gs_ic on.gif  www.freewarebox.com/screenshot_2476_clock.html  http://tv.pcworld.hu/apix/0612/Data%20thief.png  http://www.offthemarkcartoons.com/cartoons/

Editor's Notes

  1. เพิ่มแต่ละประเภทของ engine/fuel/nos .. .car
  2. Discuss each team’s UML - why draw like this…
  3. Overall UML
  4. Emphasize… in getBurnFuel() + PerformBoost()…. Else if….
  5. + Sturcture chage? .. Add , update delete + Privacy data