week 3, day 3: singleton pattern quiz status russia opportunity muddiest points – patterns se-2811...

10
Week 3, Day 3: Singleton Pattern Quiz Status Russia Opportunity Muddiest Points – Patterns SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1

Upload: pamela-gordon

Post on 18-Jan-2018

215 views

Category:

Documents


0 download

DESCRIPTION

Patterns Muddiest Point We really didn't cover any sorting algorithms and what each's benefits are Can we do an example??? Related to the quiz for below question Do we need to implement code versions of the strategy and factory method patterns?? If so how extensive and will it be similar to how we implemented in class? Implementing the methods needed for the factory method pattern. Is there a flowchart/checklist to determine which pattern is more appropriate to use? Choosing the correct design pattern What are Coupling and Cohesion and is it better to have high or low coupling or cohesion? On a quiz/test would you ask us to draw the uml of a particular general pattern, or would you just ask us to write the code? Why would we use Factory Pattern? How do you know when to use what pattern to solve a problem? Diagrams High/Low Cohesion/Coupling Class Diagram for Factory Design Pattern Nothing 3

TRANSCRIPT

Page 1: Week 3, Day 3: Singleton Pattern Quiz Status Russia Opportunity Muddiest Points – Patterns SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick

Week 3, Day 3:Singleton Pattern Quiz Status Russia Opportunity Muddiest Points – Patterns

SE-2811Slide design: Dr. Mark L. Hornick

Content: Dr. HornickErrors: Dr. Yoder

1

Page 2: Week 3, Day 3: Singleton Pattern Quiz Status Russia Opportunity Muddiest Points – Patterns SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick

Summer Study Abroad Opportunity in St. Petersburg, Russia

July 11 – 25, 2016 Two-week educational and cultural program in St. Petersburg, Russia. Curriculum is focused on the “Internet of Things (IOT)” technologies. Students will earn 3 MSOE transfer credits in CE 498 course. Online information: http://

www.sut.ru/eng/international-cooperation/summer-school Summer 2015 video: http://youtu.be/SFbVtbq67cg Freshmen, sophomores, juniors and even seniors are welcome to apply.

Cost Tuition, room & some board, excursions – 1000 Euro Airfare ≈$1100 - $1300 Student Visa - $300 Bank Transfer Fee - ≈ $45 - $60 (may be less) HIV Test for Student Visa – MSOE or your own doctor’s office

(insurance typically covers). For all information, please email Dr. Olga Imas at [email protected].

Page 3: Week 3, Day 3: Singleton Pattern Quiz Status Russia Opportunity Muddiest Points – Patterns SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick

Patterns Muddiest PointWe really didn't cover any sorting algorithms and what each's benefits areCan we do an example???Related to the quiz for below questionDo we need to implement code versions of the strategy and factory method patterns?? If so how extensive and will it be similar to how we implemented in class?Implementing the methods needed for the factory method pattern.Is there a flowchart/checklist to determine which pattern is more appropriate to use?Choosing the correct design patternWhat are Coupling and Cohesion and is it better to have high or low coupling or cohesion?On a quiz/test would you ask us to draw the uml of a particular general pattern, or would you just ask us to write the code?Why would we use Factory Pattern?How do you know when to use what pattern to solve a problem?DiagramsHigh/Low Cohesion/CouplingClass Diagram for Factory Design PatternNothing

3

Page 4: Week 3, Day 3: Singleton Pattern Quiz Status Russia Opportunity Muddiest Points – Patterns SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick

Threading Muddiest PointAll lambda examples the same code? [No, they weren't. see new slide]

Lambda examples

Lambda examplesLambda examples

When would you use a Lambda expression over an anonymous class and vice versa?

Lambda vs. Anon inner syntax

The Lambda is a Java thing, not an intelliJ thing right? Java 8whens the next quiz? Quiz

AgreeLambda examples

More examples of using lambdas (didn't get exposure in software dev 2)Lambda examples

Effectively Final?"Effectively Final"

SE-2811Dr. Mark L. Hornick

4

Page 5: Week 3, Day 3: Singleton Pattern Quiz Status Russia Opportunity Muddiest Points – Patterns SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick

Lambda Expression Syntax

Exercise: What parts does a regular method have?

Lambda Expression: A variety of syntaxes are available: <arguments> -> <method body> (Scanner in) -> {int x = in.nextInt(); return x+1;} (int x) -> x+1 () -> System.out.println(“hi”) x -> x+1

SE-2811Dr. Mark L. Hornick

5

Page 6: Week 3, Day 3: Singleton Pattern Quiz Status Russia Opportunity Muddiest Points – Patterns SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick

Lambda Expression Syntax

Different Syntax, Same result: (int x) -> {return x+1;} (int x) -> x+1 x -> x+1 new IntInterface() { public int intMethod(int x) { return x+1; } }

SE-2811Dr. Mark L. Hornick

6

Page 7: Week 3, Day 3: Singleton Pattern Quiz Status Russia Opportunity Muddiest Points – Patterns SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick

Have you ever seen a private Constructor?

class Mystery { private Mystery() { /* */ }} What happens if a constructor is private?

Why would you want this?

SE-2811Dr. Mark L. Hornick

7

Page 8: Week 3, Day 3: Singleton Pattern Quiz Status Russia Opportunity Muddiest Points – Patterns SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick

Singleton Pattern How to use a private constructor?

How to ensure only one instance is created (Single-threaded)?

Again, but if multiple threads?

SE-2811Dr. Mark L. Hornick

8

Page 9: Week 3, Day 3: Singleton Pattern Quiz Status Russia Opportunity Muddiest Points – Patterns SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick

Two kinds of Singletons Eager Lazy

Continue coding examples

SE-2811Dr. Mark L. Hornick

9

Page 10: Week 3, Day 3: Singleton Pattern Quiz Status Russia Opportunity Muddiest Points – Patterns SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick

SE-2811Dr. Mark L. Hornick

10