package com.gl051.oop;

import java.util.List;
import java.util.ArrayList;
import java.util.LinkedList;
import com.gl051.ISample;

public class Sample implements ISample {

    @Override
    public String getDescription() {
        return "OOP pillars: Encapsulation, Inheritance, Polymorphism";
    }

    @Override
    public void run() {
        try {
            // Example 1: of polymorphism using interface
            Circle circle = new Circle();
            Square square = new Square();
            DrawShape(circle);
            DrawShape(square);

            // Example 2: of polymorphis using abstrac class
            Student student = new Student("Allison", "Smith");
            Teacher teacher = new Teacher("Mark", "Jefferson");
            PrintJob(student);
            PrintJob(teacher);

            // Example 3: the List interface provided by Java util package
            ArrayList<String> arrlist = new ArrayList<>();
            LinkedList<String> lnklist = new LinkedList<>();
            PopulateList(arrlist);
            PopulateList(lnklist);
            PrintList(arrlist);
            PrintList(lnklist);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    // Programming against an Interface, argument is Shape
    private static void DrawShape(IShape shape) throws Exception{
        shape.Draw();
        Thread.sleep(2000);
    }

    // Programming against an abstract class, argument is Person
    private static void PrintJob(Person p){
        System.out.println("Person name: " + p.getFullName());
        System.out.println("Job: " + p.getOccupation());
    }

    // Practical example of programming against an interface.
    // These two methods do not rely on what implementation of List you are using,
    // the developer will pick the one more appropriate and this code still works.
    private static void PopulateList(List<String> inputList){
        inputList.clear();
        inputList.add("Bologna");
        inputList.add("Milan");
        inputList.add("Rome");
    }

    private static void PrintList(List<String> inputList){
        for(String t : inputList)
            System.out.println(t);
    }
    
    

}

@@ -373,19 +373,16 @@
 ample 1:
- of
  polymor
@@ -415,19 +415,19 @@
     
-   
+%09//
  Circle 
 circ
@@ -426,42 +426,52 @@
 cle 
-circle = new Circle();%0A   
+implements the interface (contract)%0A
         
  Squ
@@ -470,16 +470,19 @@
     
+%09//
  Square 
 squa
@@ -481,30 +481,43 @@
 are 
-square = new Square();
+implements the interface (contract)
 %0A   
@@ -539,14 +539,20 @@
 ape(
-c
+new C
 ircle
+()
 );%0A 
@@ -576,14 +576,20 @@
 ape(
-s
+new S
 quare
+()
 );%0A%0A
@@ -613,19 +613,16 @@
 ample 2:
- of
  polymor
@@ -625,16 +625,17 @@
 ymorphis
+m
  using a
@@ -640,16 +640,17 @@
  abstrac
+t
  class%0A 
@@ -659,16 +659,19 @@
         
+ //
  Student
@@ -675,50 +675,33 @@
 ent 
-student = new Student(%22Allison%22, %22Smith%22);
+IS a Person (inheritance)
 %0A   
@@ -708,16 +708,19 @@
         
+ //
  Teacher
@@ -724,51 +724,34 @@
 her 
-teacher = new Teacher(%22Mark%22, %22Jefferson%22);
+IS a Persone (inheritance)
 %0A   
@@ -772,15 +772,39 @@
 Job(
-s
+new S
 tudent
+(%22Allison%22, %22Smith%22)
 );%0A 
@@ -827,15 +827,40 @@
 Job(
-t
+new T
 eacher
+(%22Mark%22, %22Jefferson%22)
 );%0A%0A
@@ -889,56 +889,46 @@
  3: 
-the List interface provided by Java util package
+polymorphism using built-in data types
 %0A   
@@ -1308,26 +1308,106 @@
 face
-, argument is Shap
+%0A    // Each class that implements the interface will run its own%0A    // implementation at run tim
 e%0A  
@@ -1474,20 +1474,17 @@
 on%7B%0A    
-    
+%09
 shape.Dr
@@ -1572,28 +1572,61 @@
 lass
-, argument is Person
+%0A    // Encapsulation expressed by the getter methods
 %0A   
@@ -1665,25 +1665,24 @@
 rson p)%7B
-%0A
         
 System.o
@@ -1665,32 +1665,38 @@
 rson p)%7B        
+%0A    %09
 System.out.print

Clean up of the OOP sample