SlideShare ist ein Scribd-Unternehmen logo
1 von 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/

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 

Kürzlich hochgeladen (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

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/

Hinweis der Redaktion

  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