OOP real world example

0 votes

I have a simple shopping cart model with products that are based on productID, productName, Price, and Stock columns from a database. I then have a productID,ProductName,Price item class that represents the item a customer decides to order. The itemOrder class then refers to the item via productID, ProductName, Price, and quantity via a getPrice method (). The itemOrders are then stored in a Cart class, which contains methods for adding and deleting itemOrders.

Where do OOP principles come into play in any of these classes or in a conventional shopping cart system?

public class Product
{
    public int productID { get; set; }
    public string productName { get; set; }
    ...
 }
}

public class Item : Product
{

}

public class ItemOrder : Item
{
    public int itemQuantity { get; set; }
    public double getPrice(int quantity, double price)
    {
        return price = price * quantity;
    }

}
public class Cart
{

}
Jun 11 in C# by jyoti
• 1,240 points
17 views

1 answer to this question.

0 votes
This is what I believe.

OOP does not require inheritance. You have OOP if each of your classes effectively performs a single task while concealing any internal specifics from the outside world, providing a constant interface that clients cannot exploit to destroy the objects.

There's this principle called Liskov Substitution Principle and you should use inheritance if the relationship between two classes meets this principle. Read more about it here:https://en.wikipedia.org/wiki/Liskov_substitution_principle

Each of the three terms- item, product, and order are distinct and cannot be used in place of the others. All three classes must exist, but they must not share any common ancestors. Instead of using inheritance, Carts, Items, and Orders can refer to Products and to one another through references or confinement.
answered Jul 4 by krishna
• 2,540 points

Related Questions In C#

0 votes
1 answer

Encapsulation vs abstraction real world example

Encapsulation is a technique for "information concealment," ...READ MORE

answered Jun 21 in C# by jyoti
• 1,240 points
38 views
0 votes
0 answers

Use of interfaces, practical and real world example

I've been attempting to figure out what ...READ MORE

Jun 11 in C# by krishna
• 2,540 points
5 views
0 votes
1 answer

What are the differences between C, C# and C++ in terms of real-world applications?

C is a bare-bones, straightforward, and clean ...READ MORE

answered May 30 in C# by rajiv
• 1,620 points
29 views
0 votes
0 answers

C# Threading in real-world apps

Learning about threading is indeed fascinating, and ...READ MORE

Jun 11 in C# by pranav
• 2,580 points
10 views
0 votes
0 answers

Abstract Class:-Real Time Example

In a recent interview, I was asked ...READ MORE

Jun 11 in C# by pranav
• 2,580 points
21 views
0 votes
1 answer

C# - Can someone please show me a very simple example of Interfaces

Take this as example interface IFlyable { ...READ MORE

answered May 30 in C# by rajiv
• 1,620 points
24 views
0 votes
1 answer

Object Oriented Programming Basic Concept(C#)

Use this link https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers protected internal: The type or ...READ MORE

answered Jun 17 in C# by jyoti
• 1,240 points
18 views
0 votes
1 answer

Python class inherits object

Python 3.x: class MyClass(object): = new-style class class MyClass: = new-style ...READ MORE

answered Aug 30, 2018 in Python by Priyaj
• 58,080 points
247 views
0 votes
1 answer

What is the purpose of inner class in Python?

Advantages of inner class: Logical grouping of classes: ...READ MORE

answered Feb 7, 2019 in Python by SDeb
• 13,300 points
1,237 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP