SlideShare a Scribd company logo
1 of 11
Download to read offline
Architecture - Part II
Next on the agenda is integrating the model that we developed with the UI that we built…
Label currentOrderValue = new Label("Your Order: " +
Restaurant.getInstance().formatCurrency(0),
"YourOrder");
Restaurant.getInstance().cart.get().
dishesQuantity.addChangeListener(pl -> {
double totalPriceValue = 0;
for(Map.Entry<Dish, Integer> currentDish :
Restaurant.getInstance().cart.get().dishesQuantity) {
totalPriceValue += (currentDish.getKey().price.get() *
currentDish.getValue());
}
currentOrderValue.setText("Your Order: " +
Restaurant.getInstance().
formatCurrency(totalPriceValue));
revalidate();
});
Base Form
First, I didn’t mention the format currency call. Initially when I started working on the code I used the L10NManager to format the code which made sense at a glance.
However, currency is something we get from the restaurant itself and it should handle the currency type.

Adding the dishes is code we already have however, this second block of code is pretty cool…
Label currentOrderValue = new Label("Your Order: " +
Restaurant.getInstance().formatCurrency(0),
"YourOrder");
Restaurant.getInstance().cart.get().
dishesQuantity.addChangeListener(pl -> {
double totalPriceValue = 0;
for(Map.Entry<Dish, Integer> currentDish :
Restaurant.getInstance().cart.get().dishesQuantity) {
totalPriceValue += (currentDish.getKey().price.get() *
currentDish.getValue());
}
currentOrderValue.setText("Your Order: " +
Restaurant.getInstance().
formatCurrency(totalPriceValue));
revalidate();
});
Base Form
First I bind a listener to the dish quantity which allows me to track changes to the map of dishes to the quantity of each. That means that every time a dish is added or
removed in the map of dishes (regardless of the source of the change) we can get an event and recalculate the amount in the order.

Updating the amount is literally as trivial as looping over the dishes and adding up the amounts then setting it to the label.

Notice that we call revalidate at the bottom since the label might have a longer string as a result and we might need to enlarge the space allocated for it
private void updatePrice() {
double totalPriceValue = 0;
for(Map.Entry<Dish, Integer> currentDish :
Restaurant.getInstance().cart.get().dishesQuantity) {
totalPriceValue += (currentDish.getKey().price.get() * currentDish.getValue());
}
totalPrice.setText("Total: " + Restaurant.getInstance().formatCurrency(totalPriceValue));
totalPrice.getParent().revalidate();
}
private Container createShoppingCartContainer(Dish di, int quantity) {
// snipped…
Container dishContainer = BoxLayout.encloseX(
FlowLayout.encloseMiddle(quantityButton),
new Label(di.thumbnail.get(), "UnmarginedLabel"),
FlowLayout.encloseMiddle(
BoxLayout.encloseY(
new Label(di.name.get(), "DishCheckoutTitle"),
new Label(Restaurant.getInstance().formatCurrency(di.price.get()), "CheckoutPrice")
)
)
);
Checkout Form
We have very similar code in the checkout form, it updates the total value based on the dish map. In this case we don’t need the listeners since the checkout form only
provides one way to edit the data.

The dish container hasn’t changed much so I snipped out most of the code
quantityButton.addActionListener(e -> {
if(quantityButton.getSelectedString().equals(PICKER_STRINGS[0])) {
Display.getInstance().callSerially(() -> {
dishContainer.setX(Display.getInstance().getDisplayWidth());
Container p = dishContainer.getParent();
p.animateUnlayoutAndWait(250, 255);
dishContainer.remove();
p.animateLayoutAndWait(200);
updatePrice();
});
} else {
updatePrice();
}
});
return dishContainer;
}
Checkout Form
However the animation portion of the removal now needs to update the price after the animation completed. Notice we call updatePrice only after the animation so the
repaint of the price won’t interfere with the running animation
Restaurant r = Restaurant.getInstance();
Coord crd = new Coord(r.latitude.get(), r.longitude.get());
MapContainer map = new MapContainer(“google-key");
map.addMarker(null, crd, r.name.get(), r.tagline.get(), null);
map.setCameraPosition(crd);
TextArea address = new TextArea(r.address.get());
address.setEditable(false);
address.setUIID("MapAddressText");
Button phone = new Button("", "ShoppingCart");
FontImage.setMaterialIcon(phone, FontImage.MATERIAL_CALL);
phone.addActionListener(e -> Display.getInstance().dial(r.phone.get()));
Button navigate = new Button("", "ShoppingCart");
FontImage.setMaterialIcon(navigate, FontImage.MATERIAL_NAVIGATION);
navigate.addActionListener(e ->
Display.getInstance().openNativeNavigationApp(r.navigationAddress.get()));
Contact Us Form
The contact us form is practically the same as before and the only major difference is that the formerly hardcoded data is now entirely from the restaurant class.
List<String> l = new List<String>(new DefaultListModel<>(
Restaurant.getInstance().
menu.get().
categories.asList()))
protected Container createContent() {
Container c = new Container(BoxLayout.y());
for(Dish currentDish : Restaurant.getInstance().menu.get().dishes) {
c.add(createDishContainer(currentDish));
}
c.setScrollableY(true);
c.setScrollVisible(false);
return c;
}
order.addActionListener(e -> {
Order o = Restaurant.getInstance().cart.get();
if(o.dishesQuantity.get(dish) != null) {
o.dishesQuantity.put(dish, o.dishesQuantity.get(dish) + 1);
} else {
o.dishesQuantity.put(dish, 1);
}
});
Main Menu Form
The main menu form has 3 interesting pieces of code I’d like to focus on. First the code to create the categories list is no longer hardcoded
List<String> l = new List<String>(new DefaultListModel<>(
Restaurant.getInstance().
menu.get().
categories.asList()))
protected Container createContent() {
Container c = new Container(BoxLayout.y());
for(Dish currentDish : Restaurant.getInstance().menu.get().dishes) {
c.add(createDishContainer(currentDish));
}
c.setScrollableY(true);
c.setScrollVisible(false);
return c;
}
order.addActionListener(e -> {
Order o = Restaurant.getInstance().cart.get();
if(o.dishesQuantity.get(dish) != null) {
o.dishesQuantity.put(dish, o.dishesQuantity.get(dish) + 1);
} else {
o.dishesQuantity.put(dish, 1);
}
});
Main Menu Form
The second part is the content container which loops over the dishes in the main menu and places them into the UI. Unlike the previous code this now uses the
restaurant model to show the data
List<String> l = new List<String>(new DefaultListModel<>(
Restaurant.getInstance().
menu.get().
categories.asList()))
protected Container createContent() {
Container c = new Container(BoxLayout.y());
for(Dish currentDish : Restaurant.getInstance().menu.get().dishes) {
c.add(createDishContainer(currentDish));
}
c.setScrollableY(true);
c.setScrollVisible(false);
return c;
}
order.addActionListener(e -> {
Order o = Restaurant.getInstance().cart.get();
if(o.dishesQuantity.get(dish) != null) {
o.dishesQuantity.put(dish, o.dishesQuantity.get(dish) + 1);
} else {
o.dishesQuantity.put(dish, 1);
}
});
Main Menu Form
The final part is the code which adds a dish. Order is the button you see here, it adds the item to the order total. Notice that we just put a dish into the order and update
the quantity… Nothing else. The event handling code updates the subtotal of the order seamlessly!
What did we learn?
✦ Designing an object model is easier when we
already built the UI
✦ Top -> Bottom is a very convenient way to quickly
build an app
I don’t always use the top to bottom approach of development but I like it more. When I take that approach I can quickly bring non-coders into the “circle” of discussion
as the UI aspect is instantly communicable and everything else becomes far easier. 

There are always exceptions to the rule, for instance sometimes we build apps for companies that have extensive backends and no front-ends. In those cases it’s
sometimes easier to just build the mapping to the backend and then build a UI around that. 

In both cases I’m firmly in the camp of running quickly thru the design. You can’t debug a design. Unless you are building a mission critical app your time might be better
spent coding than overthinking a design
Thank You!
Thanks for watching I hope you found this educational. Please join the discussion in the comments section and let me know what you think!

More Related Content

Similar to Architecture - Part 2 - Transcript.pdf

Hello everyone,Im actually working on a fast food order program..pdf
Hello everyone,Im actually working on a fast food order program..pdfHello everyone,Im actually working on a fast food order program..pdf
Hello everyone,Im actually working on a fast food order program..pdffedosys
 
Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017
Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017
Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017Mike Nakhimovich
 
Battle of React State Managers in frontend applications
Battle of React State Managers in frontend applicationsBattle of React State Managers in frontend applications
Battle of React State Managers in frontend applicationsEvangelia Mitsopoulou
 
Extracting ui Design - part 4 - transcript.pdf
Extracting ui Design - part 4 - transcript.pdfExtracting ui Design - part 4 - transcript.pdf
Extracting ui Design - part 4 - transcript.pdfShaiAlmog1
 
I finished most of the program, but having trouble with some key fea.pdf
I finished most of the program, but having trouble with some key fea.pdfI finished most of the program, but having trouble with some key fea.pdf
I finished most of the program, but having trouble with some key fea.pdfhardjasonoco14599
 
Creating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdfCreating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdfShaiAlmog1
 
Hello everyone,Im working on my fast food order project program..pdf
Hello everyone,Im working on my fast food order project program..pdfHello everyone,Im working on my fast food order project program..pdf
Hello everyone,Im working on my fast food order project program..pdfpristiegee
 
This is a C# project . I am expected to create as this image shows. .pdf
This is a C# project . I am expected to create as this image shows. .pdfThis is a C# project . I am expected to create as this image shows. .pdf
This is a C# project . I am expected to create as this image shows. .pdfindiaartz
 
Writing Go(od) Tests (FOSDEM 2020)
Writing Go(od) Tests (FOSDEM 2020)Writing Go(od) Tests (FOSDEM 2020)
Writing Go(od) Tests (FOSDEM 2020)Nikki Attea
 
Smartwatch - something more than an additional screen for notifications?
Smartwatch - something more than an additional screen for notifications?Smartwatch - something more than an additional screen for notifications?
Smartwatch - something more than an additional screen for notifications?Railwaymen
 
Restaurant Server - Transcript.pdf
Restaurant Server - Transcript.pdfRestaurant Server - Transcript.pdf
Restaurant Server - Transcript.pdfShaiAlmog1
 
Miscellaneous Features - Part 2 - Transcript.pdf
Miscellaneous Features - Part 2 - Transcript.pdfMiscellaneous Features - Part 2 - Transcript.pdf
Miscellaneous Features - Part 2 - Transcript.pdfShaiAlmog1
 
Extracting ui Design - part 4.pdf
Extracting ui Design - part 4.pdfExtracting ui Design - part 4.pdf
Extracting ui Design - part 4.pdfShaiAlmog1
 
Restaurant Server.pdf
Restaurant Server.pdfRestaurant Server.pdf
Restaurant Server.pdfShaiAlmog1
 
How Reactive do we need to be
How Reactive do we need to beHow Reactive do we need to be
How Reactive do we need to beJana Karceska
 
12.9 Program Online shopping cart (continued) (C++)This program e.pdf
12.9 Program Online shopping cart (continued) (C++)This program e.pdf12.9 Program Online shopping cart (continued) (C++)This program e.pdf
12.9 Program Online shopping cart (continued) (C++)This program e.pdffasttracksunglass
 
Building complex User Interfaces with Sitecore and React
Building complex User Interfaces with Sitecore and ReactBuilding complex User Interfaces with Sitecore and React
Building complex User Interfaces with Sitecore and ReactJonne Kats
 
SQLite and ORM Binding - Part 2 - Transcript.pdf
SQLite and ORM Binding - Part 2 - Transcript.pdfSQLite and ORM Binding - Part 2 - Transcript.pdf
SQLite and ORM Binding - Part 2 - Transcript.pdfShaiAlmog1
 
A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...
A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...
A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...Databricks
 

Similar to Architecture - Part 2 - Transcript.pdf (20)

Hello everyone,Im actually working on a fast food order program..pdf
Hello everyone,Im actually working on a fast food order program..pdfHello everyone,Im actually working on a fast food order program..pdf
Hello everyone,Im actually working on a fast food order program..pdf
 
Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017
Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017
Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017
 
Battle of React State Managers in frontend applications
Battle of React State Managers in frontend applicationsBattle of React State Managers in frontend applications
Battle of React State Managers in frontend applications
 
Extracting ui Design - part 4 - transcript.pdf
Extracting ui Design - part 4 - transcript.pdfExtracting ui Design - part 4 - transcript.pdf
Extracting ui Design - part 4 - transcript.pdf
 
I finished most of the program, but having trouble with some key fea.pdf
I finished most of the program, but having trouble with some key fea.pdfI finished most of the program, but having trouble with some key fea.pdf
I finished most of the program, but having trouble with some key fea.pdf
 
Creating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdfCreating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdf
 
Hello everyone,Im working on my fast food order project program..pdf
Hello everyone,Im working on my fast food order project program..pdfHello everyone,Im working on my fast food order project program..pdf
Hello everyone,Im working on my fast food order project program..pdf
 
This is a C# project . I am expected to create as this image shows. .pdf
This is a C# project . I am expected to create as this image shows. .pdfThis is a C# project . I am expected to create as this image shows. .pdf
This is a C# project . I am expected to create as this image shows. .pdf
 
Writing Go(od) Tests (FOSDEM 2020)
Writing Go(od) Tests (FOSDEM 2020)Writing Go(od) Tests (FOSDEM 2020)
Writing Go(od) Tests (FOSDEM 2020)
 
Smartwatch - something more than an additional screen for notifications?
Smartwatch - something more than an additional screen for notifications?Smartwatch - something more than an additional screen for notifications?
Smartwatch - something more than an additional screen for notifications?
 
Restaurant Server - Transcript.pdf
Restaurant Server - Transcript.pdfRestaurant Server - Transcript.pdf
Restaurant Server - Transcript.pdf
 
Miscellaneous Features - Part 2 - Transcript.pdf
Miscellaneous Features - Part 2 - Transcript.pdfMiscellaneous Features - Part 2 - Transcript.pdf
Miscellaneous Features - Part 2 - Transcript.pdf
 
Extracting ui Design - part 4.pdf
Extracting ui Design - part 4.pdfExtracting ui Design - part 4.pdf
Extracting ui Design - part 4.pdf
 
Restaurant Server.pdf
Restaurant Server.pdfRestaurant Server.pdf
Restaurant Server.pdf
 
How Reactive do we need to be
How Reactive do we need to beHow Reactive do we need to be
How Reactive do we need to be
 
Day 5
Day 5Day 5
Day 5
 
12.9 Program Online shopping cart (continued) (C++)This program e.pdf
12.9 Program Online shopping cart (continued) (C++)This program e.pdf12.9 Program Online shopping cart (continued) (C++)This program e.pdf
12.9 Program Online shopping cart (continued) (C++)This program e.pdf
 
Building complex User Interfaces with Sitecore and React
Building complex User Interfaces with Sitecore and ReactBuilding complex User Interfaces with Sitecore and React
Building complex User Interfaces with Sitecore and React
 
SQLite and ORM Binding - Part 2 - Transcript.pdf
SQLite and ORM Binding - Part 2 - Transcript.pdfSQLite and ORM Binding - Part 2 - Transcript.pdf
SQLite and ORM Binding - Part 2 - Transcript.pdf
 
A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...
A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...
A Practical Approach to Building a Streaming Processing Pipeline for an Onlin...
 

More from ShaiAlmog1

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...ShaiAlmog1
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfShaiAlmog1
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfShaiAlmog1
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfShaiAlmog1
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfShaiAlmog1
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfShaiAlmog1
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfShaiAlmog1
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfShaiAlmog1
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfShaiAlmog1
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfShaiAlmog1
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfShaiAlmog1
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfShaiAlmog1
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfShaiAlmog1
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfShaiAlmog1
 

More from ShaiAlmog1 (20)

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdf
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdf
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdf
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdf
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdf
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdf
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdf
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdf
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdf
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf
 

Recently uploaded

Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...ScyllaDB
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfdanishmna97
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctBrainSell Technologies
 
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxCyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxMasterG
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentationyogeshlabana357357
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuidePixlogix Infotech
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform EngineeringMarcus Vechiato
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireExakis Nelite
 
الأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهلهالأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهلهMohamed Sweelam
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!Memoori
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfalexjohnson7307
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimaginedpanagenda
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxjbellis
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftshyamraj55
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewDianaGray10
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
How to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in PakistanHow to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in Pakistandanishmna97
 

Recently uploaded (20)

Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxCyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
الأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهلهالأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهله
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdf
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptx
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overview
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
How to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in PakistanHow to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in Pakistan
 

Architecture - Part 2 - Transcript.pdf

  • 1. Architecture - Part II Next on the agenda is integrating the model that we developed with the UI that we built…
  • 2. Label currentOrderValue = new Label("Your Order: " + Restaurant.getInstance().formatCurrency(0), "YourOrder"); Restaurant.getInstance().cart.get(). dishesQuantity.addChangeListener(pl -> { double totalPriceValue = 0; for(Map.Entry<Dish, Integer> currentDish : Restaurant.getInstance().cart.get().dishesQuantity) { totalPriceValue += (currentDish.getKey().price.get() * currentDish.getValue()); } currentOrderValue.setText("Your Order: " + Restaurant.getInstance(). formatCurrency(totalPriceValue)); revalidate(); }); Base Form First, I didn’t mention the format currency call. Initially when I started working on the code I used the L10NManager to format the code which made sense at a glance. However, currency is something we get from the restaurant itself and it should handle the currency type. Adding the dishes is code we already have however, this second block of code is pretty cool…
  • 3. Label currentOrderValue = new Label("Your Order: " + Restaurant.getInstance().formatCurrency(0), "YourOrder"); Restaurant.getInstance().cart.get(). dishesQuantity.addChangeListener(pl -> { double totalPriceValue = 0; for(Map.Entry<Dish, Integer> currentDish : Restaurant.getInstance().cart.get().dishesQuantity) { totalPriceValue += (currentDish.getKey().price.get() * currentDish.getValue()); } currentOrderValue.setText("Your Order: " + Restaurant.getInstance(). formatCurrency(totalPriceValue)); revalidate(); }); Base Form First I bind a listener to the dish quantity which allows me to track changes to the map of dishes to the quantity of each. That means that every time a dish is added or removed in the map of dishes (regardless of the source of the change) we can get an event and recalculate the amount in the order. Updating the amount is literally as trivial as looping over the dishes and adding up the amounts then setting it to the label. Notice that we call revalidate at the bottom since the label might have a longer string as a result and we might need to enlarge the space allocated for it
  • 4. private void updatePrice() { double totalPriceValue = 0; for(Map.Entry<Dish, Integer> currentDish : Restaurant.getInstance().cart.get().dishesQuantity) { totalPriceValue += (currentDish.getKey().price.get() * currentDish.getValue()); } totalPrice.setText("Total: " + Restaurant.getInstance().formatCurrency(totalPriceValue)); totalPrice.getParent().revalidate(); } private Container createShoppingCartContainer(Dish di, int quantity) { // snipped… Container dishContainer = BoxLayout.encloseX( FlowLayout.encloseMiddle(quantityButton), new Label(di.thumbnail.get(), "UnmarginedLabel"), FlowLayout.encloseMiddle( BoxLayout.encloseY( new Label(di.name.get(), "DishCheckoutTitle"), new Label(Restaurant.getInstance().formatCurrency(di.price.get()), "CheckoutPrice") ) ) ); Checkout Form We have very similar code in the checkout form, it updates the total value based on the dish map. In this case we don’t need the listeners since the checkout form only provides one way to edit the data.
 The dish container hasn’t changed much so I snipped out most of the code
  • 5. quantityButton.addActionListener(e -> { if(quantityButton.getSelectedString().equals(PICKER_STRINGS[0])) { Display.getInstance().callSerially(() -> { dishContainer.setX(Display.getInstance().getDisplayWidth()); Container p = dishContainer.getParent(); p.animateUnlayoutAndWait(250, 255); dishContainer.remove(); p.animateLayoutAndWait(200); updatePrice(); }); } else { updatePrice(); } }); return dishContainer; } Checkout Form However the animation portion of the removal now needs to update the price after the animation completed. Notice we call updatePrice only after the animation so the repaint of the price won’t interfere with the running animation
  • 6. Restaurant r = Restaurant.getInstance(); Coord crd = new Coord(r.latitude.get(), r.longitude.get()); MapContainer map = new MapContainer(“google-key"); map.addMarker(null, crd, r.name.get(), r.tagline.get(), null); map.setCameraPosition(crd); TextArea address = new TextArea(r.address.get()); address.setEditable(false); address.setUIID("MapAddressText"); Button phone = new Button("", "ShoppingCart"); FontImage.setMaterialIcon(phone, FontImage.MATERIAL_CALL); phone.addActionListener(e -> Display.getInstance().dial(r.phone.get())); Button navigate = new Button("", "ShoppingCart"); FontImage.setMaterialIcon(navigate, FontImage.MATERIAL_NAVIGATION); navigate.addActionListener(e -> Display.getInstance().openNativeNavigationApp(r.navigationAddress.get())); Contact Us Form The contact us form is practically the same as before and the only major difference is that the formerly hardcoded data is now entirely from the restaurant class.
  • 7. List<String> l = new List<String>(new DefaultListModel<>( Restaurant.getInstance(). menu.get(). categories.asList())) protected Container createContent() { Container c = new Container(BoxLayout.y()); for(Dish currentDish : Restaurant.getInstance().menu.get().dishes) { c.add(createDishContainer(currentDish)); } c.setScrollableY(true); c.setScrollVisible(false); return c; } order.addActionListener(e -> { Order o = Restaurant.getInstance().cart.get(); if(o.dishesQuantity.get(dish) != null) { o.dishesQuantity.put(dish, o.dishesQuantity.get(dish) + 1); } else { o.dishesQuantity.put(dish, 1); } }); Main Menu Form The main menu form has 3 interesting pieces of code I’d like to focus on. First the code to create the categories list is no longer hardcoded
  • 8. List<String> l = new List<String>(new DefaultListModel<>( Restaurant.getInstance(). menu.get(). categories.asList())) protected Container createContent() { Container c = new Container(BoxLayout.y()); for(Dish currentDish : Restaurant.getInstance().menu.get().dishes) { c.add(createDishContainer(currentDish)); } c.setScrollableY(true); c.setScrollVisible(false); return c; } order.addActionListener(e -> { Order o = Restaurant.getInstance().cart.get(); if(o.dishesQuantity.get(dish) != null) { o.dishesQuantity.put(dish, o.dishesQuantity.get(dish) + 1); } else { o.dishesQuantity.put(dish, 1); } }); Main Menu Form The second part is the content container which loops over the dishes in the main menu and places them into the UI. Unlike the previous code this now uses the restaurant model to show the data
  • 9. List<String> l = new List<String>(new DefaultListModel<>( Restaurant.getInstance(). menu.get(). categories.asList())) protected Container createContent() { Container c = new Container(BoxLayout.y()); for(Dish currentDish : Restaurant.getInstance().menu.get().dishes) { c.add(createDishContainer(currentDish)); } c.setScrollableY(true); c.setScrollVisible(false); return c; } order.addActionListener(e -> { Order o = Restaurant.getInstance().cart.get(); if(o.dishesQuantity.get(dish) != null) { o.dishesQuantity.put(dish, o.dishesQuantity.get(dish) + 1); } else { o.dishesQuantity.put(dish, 1); } }); Main Menu Form The final part is the code which adds a dish. Order is the button you see here, it adds the item to the order total. Notice that we just put a dish into the order and update the quantity… Nothing else. The event handling code updates the subtotal of the order seamlessly!
  • 10. What did we learn? ✦ Designing an object model is easier when we already built the UI ✦ Top -> Bottom is a very convenient way to quickly build an app I don’t always use the top to bottom approach of development but I like it more. When I take that approach I can quickly bring non-coders into the “circle” of discussion as the UI aspect is instantly communicable and everything else becomes far easier. 
 There are always exceptions to the rule, for instance sometimes we build apps for companies that have extensive backends and no front-ends. In those cases it’s sometimes easier to just build the mapping to the backend and then build a UI around that. In both cases I’m firmly in the camp of running quickly thru the design. You can’t debug a design. Unless you are building a mission critical app your time might be better spent coding than overthinking a design
  • 11. Thank You! Thanks for watching I hope you found this educational. Please join the discussion in the comments section and let me know what you think!