Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not commit this file

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.suggest.showWords": false,
"editor.suggest.showKeywords": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.restaurant.burgerfactory;

public class BeefBurger implements Burger {
@Override
public void prepare() {
System.out.println("Preparing a Beef Burger");
}

}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a simple factory not abstract factory

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.restaurant.burgerfactory;

public class BeefBurgerRestaurant {

public Burger createBurger(String request) {
if (request.equalsIgnoreCase("BEEF")) {
return new BeefBurger();
} else {
return null;

}

}
}
5 changes: 5 additions & 0 deletions Harshad-LLD-hw/Abstract Factory Design Pattern/Burger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.restaurant.burgerfactory;

interface Burger {
void prepare();
}
8 changes: 8 additions & 0 deletions Harshad-LLD-hw/Abstract Factory Design Pattern/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.restaurant.burgerfactory;

public class Main {
public static void main() {
Restaurant restaurant = new VeggieBurgerRestaurant();
Burger burger = restaurant.orderBurger("Veggie");
}
}
13 changes: 13 additions & 0 deletions Harshad-LLD-hw/Abstract Factory Design Pattern/Restaurant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.restaurant.burgerfactory;

abstract class Restaurant {
public Burger orderBurger(String request) {
Burger burger = createBurger(request);
burger.prepare();
return burger;
}
abstract Burger createBurger(String request);
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.restaurant.burgerfactory;

public class VeggieBurger implements Burger {
@Override
public void prepare() {
System.out.println("Preparing a Veggie Burger");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.restaurant.burgerfactory;


public class VeggieBurgerRestaurant extends Restaurant {
@Override
public Burger createBurger(String request) {
if (request.equalsIgnoreCase("veggie")) {
return new VeggieBurger();
} else {
return null;
}

}

}
5 changes: 5 additions & 0 deletions Harshad-LLD-hw/DesignPatterns/Builder/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Harshad-LLD-hw/DesignPatterns/Builder/.idea/misc.xml

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not commit any xml file

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Harshad-LLD-hw/DesignPatterns/Builder/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Harshad-LLD-hw/DesignPatterns/Builder/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Harshad-LLD-hw/DesignPatterns/Builder/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.

public class Main {
public static void main(String[] args) {

Person person = new PersonBuilder()
.name("Harshad")
.email("xyz@gmail.com")
.contact("9999999999")
.build();

System.out.println(person.getName() + " " +person.getContact() + " " + person.getEmail());

}
}
29 changes: 29 additions & 0 deletions Harshad-LLD-hw/DesignPatterns/Builder/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
public class Person {
String name;
String email;
String contact;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getContact() {
return contact;
}

public void setContact(String contact) {
this.contact = contact;
}
}
26 changes: 26 additions & 0 deletions Harshad-LLD-hw/DesignPatterns/Builder/PersonBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
public class PersonBuilder {
private final Person person;

public PersonBuilder(){
this.person = new Person();
}

public PersonBuilder name(String name){
this.person.setName(name);
return this;
}

public PersonBuilder contact(String contact) {
this.person.setContact(contact);
return this;
}

public PersonBuilder email(String email){
this.person.setEmail(email);
return this;
}

public Person build(){
return this.person;
}
}
11 changes: 11 additions & 0 deletions Harshad-LLD-hw/DesignPatterns/Builder/PersonIdentity.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
10 changes: 10 additions & 0 deletions Harshad-LLD-hw/DesignPatterns/Singleton/LogPrinter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import java.util.List;

public class LogPrinter {
public void printLog(List<String> logs) {
System.out.println("---- Printing Order ----");
for (String log : logs) {
System.out.println(log);
}
}
}
34 changes: 34 additions & 0 deletions Harshad-LLD-hw/DesignPatterns/Singleton/Logger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import java.util.List;
import java.util.ArrayList;

public class Logger {

private List<String> L1;
private static Logger instance;


private Logger () {
L1 = new ArrayList<>();
}

public static synchronized Logger getInstance() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the basic implementation, please add with double checking and the Bill Pugh method as well

if (instance == null) {
synchronized (Logger.class) {
if (instance == null) {
instance = new Logger();
}
}
}
return instance;
}

public void log(String messages) {
System.out.println(messages);
L1.add(messages);
}

public List<String> getLogs() {
return L1;
}

}
38 changes: 38 additions & 0 deletions Harshad-LLD-hw/DesignPatterns/Singleton/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Logger log1 = Logger.getInstance();
Scanner scanner = new Scanner(System.in);

System.out.print("Enter to input the menu: ");
String message = scanner.nextLine();

if (message.equalsIgnoreCase("Burger")){
log1.log("Burger Created");
log1.log("Fries Added");
}


Logger log2 = Logger.getInstance();


System.out.print("Enter to add drinks and Tacos : ");
String msg2 = scanner.nextLine();
if (msg2.equalsIgnoreCase("tacos")) {
log2.log("Drink Added");
}

System.out.print("Enter to see the order: ");
String message1 = scanner.nextLine();

if (message1.equalsIgnoreCase("order")) {
LogPrinter pri1 = new LogPrinter();
pri1.printLog(log1.getLogs());}

// LogPrinter pri2 = new LogPrinter();

// pri2.printLog(log2.getLogs());
}

}