russkiymalchik / code-refactoring-22-23

0 stars 0 forks source link

Primitive Obsession_Lab1_Rev_Hotel Management #15

Open russkiymalchik opened 1 year ago

russkiymalchik commented 1 year ago

Primitive obsession refers to a code smell or anti-pattern in programming where primitive data types, such as strings or integers, are excessively used to represent complex domain concepts or data structures.

Example 1
ref : class "Food" ``` int itemno; int quantity; float price; Food(int itemno,int quantity) ``` The code relies on primitive types (int and float) to represent the item number, quantity, and price.
Example 2
ref : class "Hotel" ``` static void bill(int rn,int rtype) static void deallocate(int rn,int rtype) { int j; char w; ``` The code uses primitive types (int, char) to represent various entities
Example 3
ref : main class ``` int ch,ch2; char wish; x: do{ System.out.println("\nEnter your choice :\n1.Display room details\n2.Display room availability \n3.Book\n4.Order food\n5.Checkout\n6.Exit\n"); ch = sc.nextInt(); switch(ch){ case 1: System.out.println("\nChoose room type :\n1.Luxury Double Room \n2.Deluxe Double Room \n3.Luxury Single Room \n4.Deluxe Single Room\n"); ch2 = sc.nextInt(); Hotel.features(ch2); break; case 2:System.out.println("\nChoose room type :\n1.Luxury Double Room \n2.Deluxe Double Room \n3.Luxury Single Room\n4.Deluxe Single Room\n"); ch2 = sc.nextInt(); Hotel.availability(ch2); break; case 3:System.out.println("\nChoose room type :\n1.Luxury Double Room \n2.Deluxe Double Room \n3.Luxury Single Room\n4.Deluxe Single Room\n"); ch2 = sc.nextInt(); Hotel.bookroom(ch2); break; ``` The code uses primitive types like integers and characters to represent various concepts such as room numbers and user input.