OOP- Based on objects
Useful for analysis,design,coding.
OOP is a methadology to design a program using objects.
Class-is a blueprint from which objects are created.
Method- is a coolection of statements that perform some specific task and return
result to the caller.
Objects- Real world entities that has their own properties and behaviours.
Overview of OOP:
Data hiding is a basic principle of OOP.
Objects are created by a class is an instance
of that class.
Class Relations:
� has-a
� is-a(inheritance)
final keyword is used as a constant so you cant change its value.
======================================
class CreditCard {
private final long cardNumber;
CreditCard(long cardNumber){
[Link] = cardNumber;
}
}
public class Customer {
private final String name;
private CreditCard creditCard;
public Customer(String name,long ccNumber){
[Link]=name;
[Link]= new CreditCard( ccNumber);
}
}
public class Product {
private final String name;
private int price;
public Product(String name,int price){
[Link]= name;
[Link] = price;
}
public int getPrice() {
return price;
}
}
public class ShoppingCart {
private List<Product> products = new ArrayList<>();
public void addProduct(Product product) {
[Link](product);
}
public int getTotalCost() {
return [Link]()
.mapToInt(Product::getPrice)
.sum();
}
}