Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package HW1.violations.airbnb;

public interface BookingService {
int calculateTotalPrice(Hotel hotel, int numberOfNights);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package HW1.violations.airbnb;

public class BookingServiceImpl implements BookingService {
@Override
public int calculateTotalPrice(Hotel hotel, int numberOfNights) {
int totalPrice = hotel.pricePerNight * numberOfNights;
return totalPrice;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package HW1.violations.airbnb;

public class DiscountedHotel extends Hotel {
public int pricePerNight = super.pricePerNight/2;
@Override public int getPricePerNight() {
return this.pricePerNight;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package HW1.violations.airbnb;

public class FancyHotel extends Hotel {
public int pricePerNight = super.pricePerNight*2;
@Override public int getPricePerNight() {
return this.pricePerNight;
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package HW1.violations.airbnb;

public class Hotel {
public int pricePerNight = 100;
public int getPricePerNight() {
return this.pricePerNight;
}
}
18 changes: 18 additions & 0 deletions homework/src/HW1/submissions/partA/oliverzeyen/airbnb/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package HW1.violations.airbnb;

public class Main {
public static void main(String[] args) {
Hotel regularHotel = new Hotel();
DiscountedHotel discountedHotel = new DiscountedHotel();
FancyHotel fancyHotel = new FancyHotel();

BookingService bookingService = new BookingServiceImpl();
int regularHotelTotalPrice = bookingService.calculateTotalPrice(regularHotel, 3);
int discountedHotelTotalPrice = bookingService.calculateTotalPrice(discountedHotel, 3);
int fancyHotelPrice = bookingService.calculateTotalPrice(fancyHotel, 3);

System.out.println("Regular Hotel Total Price: $" + regularHotelTotalPrice);
System.out.println("Discounted Hotel Total Price: $" + discountedHotelTotalPrice);
System.out.println("Fancy Hotel Total Price: $" + fancyHotelPrice);
}
}
22 changes: 22 additions & 0 deletions homework/src/HW1/submissions/partA/oliverzeyen/airbnb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
airbnb

violates SRP (S)
How? To me, it seems like Hotels and DiscountedHotels should not be able to calculate the price depending on their stay. I think having a total amount is fine per night, but the actual calculation should be left to the BookingSerivce, as BookingService serves as a useless middleman in this case. Assuming that this is a specific cut out of a much larger, fully fleshed out class, it can be very apparent why this could be a bad thing. Essentially, a Hotel's job would/should be more on the lines of the information about the Hotel, rather than calculating your exact stay. While a price per night is useful and important to a hotel, we can use bookingservice to calculate the number of days we would spend in combination with the price point grabbed from each hotel.

violates OCP (O)
How? Any changes made to hotel's pricing, directly changes the pricing of other hotels. So, if you made the hotel $50 for the stay, and you tried to use the discountedhotel, you could potentially get a free stay. Assuming that these are two completely different hotels, unless they are somehow connected, it makes much less sense for a discountedhotel to be directly connected with a hotel.

violates LSP (L)
How? A DiscountedHotel cannot be substituted for Hotel without there being the possibility for drastic changes. It could easily result in expected behavior especially with such a simple change. Even though said simple change seems "simple", the actual calculations are done behind the scenes, and this makesway for many possiblities for error.

approach:

first, separate their responsibilities.
1. Make hotel not have the specific ability to calculate your exact stay. Instead, it has the responsibility of imagining one night at the hotel.
2. BookingService now has the sole responsibility of calculating your entire stay.
second, ensure cohesion in the event of price changes
1. While this still seems a bit weird to have hotel prices deeply connected, their prices can be connected in a less hard-wired way.
1a. Make a sort of formula for accounting for discounts or pricey hotels
1b. Give each hotel a version of the original hotel's price that will maintain consistency

Added a new hotel, FancyHotel, to represent a more pricey point. In this case, I doubled the price of a normal hotel, while the discountedhotel received a price change of half the price of a normal hotel.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package HW1.violations.doordash;

public class Customer {
private String name;

public Customer(String name) {
this.name = name;
}

public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package HW1.violations.doordash;

public interface DeliveryService {
void deliverFood(Restaurant restaurant, Customer customer);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package HW1.violations.doordash;

public class FoodDeliveryService implements DeliveryService {
@Override
public void deliverFood(Restaurant restaurant, Customer customer) {
System.out.println("Food delivered from " + restaurant.getName() + " to " + customer.getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package HW1.violations.doordash;

public class FoodTrackingService implements TrackingService {
@Override
public void trackPackage(String trackingNumber) {
System.out.println("Package with tracking number " + trackingNumber + " is being tracked.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package HW1.violations.doordash;

public class OrderManager {
private FoodDeliveryService FDS;
private FoodTrackingService FTS;

public OrderManager() {
FDS = new FoodDeliveryService();
FTS = new FoodTrackingService();
}

public void processOrder(Restaurant r, Customer c) {
FDS.deliverFood(r, c);
}

public void trackOrder(String trackingNumber) {
FTS.trackPackage(trackingNumber);
}
}

14 changes: 14 additions & 0 deletions homework/src/HW1/submissions/partA/oliverzeyen/doordash/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
doordash

violates SRP (S)
Clear reasoning is the "and" in the fooddeliveryandtrackingservice class. One class is responsible for both delivering the food, as well as tracking the food. Those are two very complex jobs that in a high level implementation things would get extremely messy. It is best to separate things, and we can do so simply and allow for better implementation.

violates ISP (I)
When we separate things, we also have to change our interface, as the interface as it was, had given the class too many responsibilities. This is more of the effects of solving a part of SOLID, rather than a clear intial violation.

changed:

Not the best implementation but it definitely gets the idea across.
1. Separate both the interface and class that handles delivery and tracking into two
2. Create a OrderManager class that can now combine the two.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package HW1.violations.doordash;

public class Restaurant {
private String name;

public Restaurant(String name) {
this.name = name;
}

public String getName() {
return name;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package HW1.violations.doordash;

public interface TrackingService {
void trackPackage(String trackingNumber);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package HW1.violations.facebook;

class ImagePost extends TextPost {
private String imageUrl;
private boolean isImage;

@Override
public void display() {
super.display();
System.out.println("Now displaying image: " + this.getImageUrl());
}
// Constructor, getters, and setters for text

public ImagePost(String text, String imageUrl, boolean isImage) {
super(text);
this.imageUrl = imageUrl;
this.isImage = isImage;
}

public String getImageUrl() {
return imageUrl;
}

public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}

public boolean isImage() {
return isImage;
}

public void setImage(boolean image) {
isImage = image;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package HW1.violations.facebook;

public interface Post {
public void display();
}
14 changes: 14 additions & 0 deletions homework/src/HW1/submissions/partA/oliverzeyen/facebook/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
facebook

post 1 violates the open closed principle (O)
It has such limited functionality that it makes modifying it very difficult.

post 2 vioaltes the single responsibility principle (S)
In complete contrast, post2 has way too many things that it needs to handle, which ends up making things a mess.

The two posts, are either bone dry and like a rock which makes it hard to modify, or is a complete mess and tangled which makes it harder to manage. They are both weirdly named which im sure was for the sake of the homework.

changes:

1. Very simply, we can separate each post into it's own type. This makes it so a text post wouldn't have to deal with video urls.
2. Add a post for each type of post that can be made.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package HW1.violations.facebook;

public class TextPost implements Post{
private String text;

public TextPost(String text) {
this.text = text;
}

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}

public void display() {
System.out.println(text);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package HW1.violations.facebook;

class VideoPost extends TextPost{
private boolean isVideo;
private String videoUrl;

@Override
public void display() {
super.display();
System.out.println("Now watching: " + this.getVideoUrl());
}

// Constructor, getters, and setters for text

public VideoPost(String text, boolean isVideo, String videoUrl) {
super(text);
this.isVideo = isVideo;
this.videoUrl = videoUrl;
}

public String getVideoUrl() {
return videoUrl;
}

public void setVideoUrl(String videoUrl) {
this.videoUrl = videoUrl;
}
public boolean isVideo() {
return isVideo;
}
public void setVideo(boolean video) {
isVideo = video;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package HW1.violations.facebook;

class VotePost extends TextPost {
private String text;
private String prompt;
private int voteYes;
private int voteNo;


// Constructor, getters, and setters for text

public VotePost(String text, String prompt) {
super(text);
this.prompt = prompt;
voteYes = 0;
voteNo = 0;
}

public void votedYes() {
voteYes++;
}

public void votedNo() {
voteNo++;
}

@Override
public void display() {
super.display();
System.out.println("Prompt: " + this.prompt + "\nYes votes: " + voteYes + "\nNo votes:" + voteNo);
}
}
13 changes: 13 additions & 0 deletions homework/src/HW1/submissions/partA/oliverzeyen/paypal/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package HW1.violations.paypal;

public class Account {
private String accountID;

public Account(String accountID) {
this.accountID = accountID;
}

public String getAccountID() {
return accountID;
}
}
10 changes: 10 additions & 0 deletions homework/src/HW1/submissions/partA/oliverzeyen/paypal/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package HW1.violations.paypal;

public class Main {
public static void main(String[] args) {
PaymentProcessor paymentProcessor = new PaymentProcessor();
Account account = new Account("1");
paymentProcessor.processPayment(account,100.0);
paymentProcessor.processRequest(account, 50.0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package HW1.violations.paypal;

public interface PayPal {
void processPayment(Account account, double amount);
void processRequest(Account account, double amount);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package HW1.violations.paypal;

public class PayPalGateway implements PayPal {
@Override
public void processPayment(Account account, double amount) {
System.out.println("Processing payment of $" + amount + " for acocunt " + account.getAccountID() + " using PayPal.");
}

@Override
public void processRequest(Account account, double amount) {
System.out.println("Processing request of $" + amount + " for account " + account.getAccountID() + " using PayPal.");
}
}
Loading