{"id":27331,"date":"2014-07-15T11:09:10","date_gmt":"2014-07-15T08:09:10","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=27331"},"modified":"2023-12-05T15:45:13","modified_gmt":"2023-12-05T13:45:13","slug":"abstraction-in-java","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2014\/07\/abstraction-in-java.html","title":{"rendered":"Abstraction in Java &#8211; The ULTIMATE Tutorial (PDF Download)"},"content":{"rendered":"<p><strong>EDITORIAL NOTE<\/strong>: In this post, we feature a comprehensive Abstraction in Java Tutorial. Abstraction occurs during class level design, with the objective of hiding the implementation complexity of how the the features offered by an API \/ design \/ system were implemented, in a sense simplifying the &#8216;interface&#8217; to access the underlying implementation. This process can be repeated at increasingly &#8216;higher&#8217; levels (layers) of abstraction, which enables large systems to be built without increasing the complexity of code and understanding, at higher layers.<\/p>\n<div class=\"toc\">\n<h3>Table Of Contents<\/h3>\n<dl>\n<dt><a href=\"#introduction\">1. Introduction<\/a><\/dt>\n<dt><a href=\"#interfaces\">2. Interfaces<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#defining\">2.1. Defining Interfaces<\/a><\/dt>\n<dt><a href=\"#implementing\">2.2. Implementing Interfaces<\/a><\/dt>\n<dt><a href=\"#using\">2.3. Using Interfaces<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#abstract_classes\">3. Abstract Classes<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#defining_abstract_classes\">3.1. Defining Abstract Classes<\/a><\/dt>\n<dt><a href=\"#extending_abstract_classes\">3.2. Extending Abstract Classes<\/a><\/dt>\n<dt><a href=\"#using_abstract_classes\">3.3. Using Abstract Classes<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#example\">4. A Worked Example &#8211; Payments System<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#payee\">4.1. The Payee Interface<\/a><\/dt>\n<dt><a href=\"#system\">4.2. The Payment System<\/a><\/dt>\n<dt><a href=\"#employee\">4.3. The Employee Classes<\/a><\/dt>\n<dt><a href=\"#the_application\">4.4. The Application<\/a><\/dt>\n<dt><a href=\"#handling_bonuses\">4.5. Handling Bonuses<\/a><\/dt>\n<dt><a href=\"#contracting_companies\">4.6. Contracting Companies<\/a><\/dt>\n<dt><a href=\"#taxation\">4.7. Advanced Functionality: Taxation<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#Conclusion\">5. Conclusion<\/a><\/dt>\n<\/dl>\n<\/div>\n<p>&nbsp;<\/p>\n<h1><a name=\"introduction\"><\/a>1. Introduction<\/h1>\n<p>In this tutorial we will give an introduction to Abstraction in Java and define a simple Payroll System using Interfaces, Abstract Classes and Concrete Classes.<\/p>\n<p>There are two levels of abstraction in Java &#8211; <strong>Interfaces<\/strong>, used to define expected behaviour and <strong>Abstract Classes<\/strong>, used to define incomplete functionality.<\/p>\n<p>We will now look at these two different types of abstraction in detail.<\/p>\n<h1><a name=\"interfaces\"><\/a>2. Interfaces<\/h1>\n<p>An interface is like a contract. It is a promise to provide certain behaviours and all classes which implement the interface guarantee to also implement those behaviours. To define the expected behaviours the interface lists a number of method signatures. Any class which uses the interface can rely on those methods being implemented in the runtime class which implements the interface. This allows anyone using the interface to know what functionality will be provided without having to worry about how that functionality will actually be achieved. The implementation details are hidden from the client, this is a crucial benefit of abstraction.<\/p>\n<h2><a name=\"defining\"><\/a>2.1. Defining Interfaces<\/h2>\n<p>You can use the keyword <strong>interface<\/strong> to define an interface:<\/p>\n<pre class=\"brush:java\">public interface MyInterface {\n\nvoid methodA();\n\nint methodB();\n\nString methodC(double x, double y);\n\n}<\/pre>\n<p>Here we see an interface called MyInterface defined, note that you should use the same case conventions for Interfaces that you do for Classes. MyInterface defines 3 methods, each with different return types and parameters. You can see that none of these methods have a body; when working with interfaces we are only interested in defining the expected behaviour, not with it\u2019s implementation. <em>Note: Java 8 introduced the ability to create a default implementation for interface methods, however we will not cover that functionality in this tutorial.<\/em><\/p>\n<p>Interfaces can also contain state data by the use of member variables:<\/p>\n<pre class=\"brush:java\">public interface MyInterfaceWithState {\n\n\tint someNumber;\n\n\tvoid methodA();\n\n}<\/pre>\n<p>All the methods in an interface are public by default and in fact you can\u2019t create a method in an interface with an access level other than public.<\/p>\n<h2><a name=\"implementing\"><\/a>2.2. Implementing Interfaces<\/h2>\n<p>Now we have defined an interface we want to create a class which will provide the implementation details of the behaviour we have defined. We do this by writing a new class and using the <code>implements<\/code> keyword to tell the compiler what interface this class should implement.<\/p>\n<pre class=\"brush:java\">public class MyClass implements MyInterface {\n\n\tpublic void methodA() {\n\t\tSystem.out.println(\"Method A called!\");\n\t}\n\n\tpublic int methodB() {\n\t\treturn 42;\n\t}\n\n\tpublic String methodC(double x, double y) {\n\t\treturn \"x = \" + x + \", y = \" y;\n\t}\n\n}<\/pre>\n<p>We took the method signatures which we defined in <code>MyInterface<\/code> and gave them bodies to implement them. We just did some arbitrary silliness in the implementations but it\u2019s important to note that we could have done anything in those bodies, as long as they satisfied the method signatures. We could also create as many implementing classes as we want, each with different implementation bodies of the methods from <code>MyInterface<\/code>.<\/p>\n<p>We implemented all the methods from <code>MyInterface<\/code> in <code>MyClass<\/code> and if we failed to implement any of them the compiler would have given an error. This is because the fact that MyClass implements MyInterface means that MyClass is guaranteeing to provide an implementation for each of the methods from MyInterface. This lets any clients using the interface rely on the fact that at runtime there will be an implementation in place for the method it wants to call, guaranteed.<\/p>\n<h2><a name=\"using\"><\/a>2.3. Using Interfaces<\/h2>\n<p>To call the methods of the interface from a client we just need to use the dot (.) operator, just like with the methods of classes:<\/p>\n<pre class=\"brush:java\">MyInterface object1 = new MyClass();\nobject1.methodA(); \/\/ Guaranteed to work<\/pre>\n<p>We see something unusual above, instead of something like <code>MyClass object1 = new MyClass();<\/code> (which is perfectly acceptable) we declare object1 to be of type MyInterface. This works because MyClass is an implementation of MyInterface, wherever we want to call a method defined in MyInterface we know that MyClass will provide the implementation. object1 is a <strong>reference<\/strong> to any runtime object which implements MyInterface, in this case it\u2019s an instance of MyClass. If we tried to do <code>MyInterface object1 = new MyInterface()<\/code> we\u2019d get a compiler error because you can\u2019t instantiate an interface, which makes sense because there\u2019s no implementation details in the interface &#8211; no code to execute.<\/p>\n<p>When we make the call to <code>object1.methodA()<\/code> we are executing the method body defined in MyClass because the <strong>runtime type<\/strong> of object1 is MyClass, even though the reference is of type MyInterface. We can only call methods on object1 that are defined in MyInterface, for all intents and purposes we can refer to object1 as being of type MyInterface even though the runtime type is MyClass. In fact if MyClass defined another method called <code>methodD()<\/code> we couldn\u2019t call it on object1, because the compiler only knows that object1 is a reference to a MyInterface, not that it is specifically a MyClass.<\/p>\n<p>This important distinction is what lets us create different implementation classes for our interfaces without worrying which specific one is being called at runtime.<\/p>\n<p>Take the following interface:<\/p>\n<pre class=\"brush:java\">public interface OneMethodInterface {\n\n\tvoid oneMethod();\n\n}<\/pre>\n<p>It defines one void method which takes no parameters.<\/p>\n<p>Let\u2019s implement it:<\/p>\n<pre class=\"brush:java\">public class ClassA implements OneMethodInterface {\n\n\tpublic void oneMethod() {\n\t\tSystem.out.println(\"Runtime type is ClassA.\");\n\t}\n}<\/pre>\n<p>We can use this in a client just like before:<\/p>\n<pre class=\"brush:java\">OneMethodInterface myObject = new ClassA();\nmyObject.oneMethod();<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre class=\"&quot;brush:bash\">Runtime type is ClassA.<\/pre>\n<p>Now let\u2019s make a different implementation for OneMethodInterface:<\/p>\n<pre class=\"brush:java\">public class ClassB implements OneMethodInterface {\n\t\n\tpublic void oneMethod() {\n\t\tSystem.out.println(\"The runtime type of this class is ClassB.\");\n}\n}<\/pre>\n<p>And modify our code above:<\/p>\n<pre class=\"brush:java\">OneMethodInterface myObject = new ClassA();\nmyObject.oneMethod();\nmyObject = new ClassB();\nmyObject.oneMethod();<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre class=\"brush:bash\">Runtime type is ClassA.\nThe runtime type of this class is ClassB.<\/pre>\n<p>We have successfully used the same Reference (<code>myObject<\/code>) to refer to instances of two different runtime types. The actual implementation is completely unimportant to the compiler, it just cares that <code>OneMethodInterface<\/code> is implemented, by anything, and in any way. As far as the compiler is concerned myObject is a OneMethodInterface, and <code>oneMethod()<\/code> is available, even if it\u2019s reassigned to a different instance object of a different class type. This ability to provide more than one runtime type and have it resolved at run time, rather than compile time, is called <strong>polymorphism<\/strong>.<\/p>\n<p>Interfaces define behaviour without any implementation details (ignoring Java 8) and implementing classes define all the implementation details for the classes they define, but what happens if we want a mix of the two concepts? If we want to mix some behaviour definition and some implementation together in the same place we can use an abstract class.<\/p>\n<h1><a name=\"abstract_classes\"><\/a>3. Abstract Classes<\/h1>\n<p>An abstract class is like an incomplete blueprint, it defines some of the implementation details of the class while leaving others as simple behaviour definitions to be implemented later.<\/p>\n<p>Imagine a blueprint of a house where the house is drawn in completely but there is a big empty square where the garage will go. We know there will be a garage but we don\u2019t know what it will look like. Somebody else will have to take a copy of our blueprint and draw in the garage. In fact several different people may take copies of our blueprint and draw in different types of garage. Houses built using these blueprints will all be recognizable variants of our house; the front door, the room layouts and the windows will all be identical, however the garages will all be different.<\/p>\n<p>Much like the blueprints above our abstract classes will define some methods completely, and these method implementations will be the same in all implementations of the abstract class. The abstract class will define only the signature for other methods, in much the same way that interfaces do. The method implementations for these methods will vary in the implementing classes. An implementing class of an abstract class is commonly referred to as a <strong>concrete<\/strong> class. Due to the inheritance relationship between the concrete class and the abstract class we generally say that a concrete class <strong>extends<\/strong> an abstract class, rather than implements it as we say with interfaces.<\/p>\n<p>Just like with interfaces any client code knows that if a concrete class is extending an abstract class the concrete class guarantees to provide method bodies for the abstract methods of the abstract class (the abstract class provides it\u2019s own method bodies for non-abstract methods, of course).<\/p>\n<p>Again, just like interfaces, there can be several different concrete classes of a given abstract class, each may define very different behaviours for the abstract methods of the abstract class while satisfying the contract of the abstract class. The implementation details are hidden from the client.<\/p>\n<h2><a name=\"defining_abstract_classes\"><\/a>3.1. Defining Abstract Classes<\/h2>\n<p>The keyword <strong>abstract<\/strong> is used to define both a class and its methods as abstract.<\/p>\n<pre class=\"brush:java\">public abstract class MyAbstractClass {\n\n\tprotected int someNumber = 0;\n\n\tpublic void increment() {\n\t\tsomeNumber++;\n\t}\n\n\tpublic abstract void doSomethingWithNumber();\n\n}<\/pre>\n<p>Here we have defined an abstract class called <code>MyAbstractClass<\/code> which contains an integer and provides a method for incrementing that integer. We also define an abstract method called <code>doSomethingWithNumber()<\/code>. We don\u2019t yet know what this method will do, it will be defined in any concrete classes which extend <code>MyAbstractClass<\/code>. <code>doSomethingWithNumber()<\/code> doesn\u2019t have a method body because it is abstract.<\/p>\n<p>In interfaces all the methods are public by default, however the scope of an abstract method may be public, package or protected.<\/p>\n<p>You can see that some behavioural implementation in increment() is mixed with some behavioural definition in <code>doSomethingWithNumber()<\/code> in this abstract class. Abstract classes mix some implementation with some definition. Concrete classes which extend Abstract class will reuse the implementation of <code>increment()<\/code> while guaranteeing to provide their own implementations of <code>doSomethingWithNumber()<\/code>.<\/p>\n<h2><a name=\"extending_abstract_classes\"><\/a>3.2. Extending Abstract Classes<\/h2>\n<p>Now that we have created an abstract class let\u2019s make a concrete implementation for it. We make concrete implementations from abstract classes by using the <strong>extends<\/strong> keyword in a class which itself is not abstract.<\/p>\n<pre class=\"brush:java\">public class MyConcreteClass extends MyAbstractClass {\n\n\tpublic void sayHello() {\n\t\tSystem.out.println(\"Hello there!\");\n}\n\n\tpublic void doSomethingWithNumber() {\n\t\tSystem.out.println(\"The number is \" + someNumber);\n}\n\n}<\/pre>\n<p>We have created a concrete class called <code>MyConcreteClass<\/code> and extended <code>MyAbstractClass<\/code>. We only needed to provide an implementation for the abstract method <code>doSomethingWithNumber()<\/code> because we <strong>inherit<\/strong> the non private member variables and methods from MyAbstractClass. If any client calls <code>increment()<\/code> on MyConcreteClass the implementation defined in MyAbstractClass will be executed. We also created a new method called <code>sayHello()<\/code> which is unique to MyConcreteClass and wouldn\u2019t be available from any other concrete class which implements MyAbstractClass.<\/p>\n<p>We can also extend <code>MyAbstractClass<\/code> with another abstract class where we don\u2019t implement <code>doSomethingWithNumber<\/code> &#8211; this means that another concrete class will have to be defined, which extends this new class in order to implement <code>doSomethingWithNumber()<\/code>.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:java\">public abstract class MyOtherAbstractClass extends MyAbstractClass {\n\n\tpublic void sayHello() {\n\t\tSystem.out.println(\"Hello there!\");\n}\n}<\/pre>\n<p>We didn\u2019t have to make any reference to doSomethingWithNumber() here, whenever we create a concrete class for MyOtherAbstractClass we will provide the implementation for doSomethingWithNumber().<\/p>\n<p>Lastly, abstract classes can themselves implement interfaces. Because the abstract class can\u2019t be instantiated itself it does not have to provide an implementation for all (or any) of the interface methods. If the abstract class does not provide an implementation for an interface method, the concrete class which extends the abstract class will have to provide the implementation.<\/p>\n<pre class=\"brush:java\">public abstract MyImplementingAbstractClass implements MyInterface {\n\t\n\tpublic void methodA() {\n\t\tSystem.out.println(\"Method A has been implemented in this abstract class\");\n\t}\n}<\/pre>\n<p>Here we see that MyImplementingAbstractClass implements MyInterface but only provides an implementation for methodA(). If any concrete class extends MyImplementingAbstractClass it will have to provide an implementation for methodB() and methodC() as defined in MyInterface.<\/p>\n<h2><a name=\"using_abstract_classes\"><\/a>3.3. Using Abstract Classes<\/h2>\n<p>Just like with Interfaces and regular classes, to call the methods of an abstract class you use the dot (.) operator.<\/p>\n<pre class=\"brush:java\">MyAbstractClass object1 = new MyConcreteClass();\nobject1.increment();\nobject1.doSomethingWithNumber();<\/pre>\n<p>Again we see that object1 is a reference to an instance that provides a concrete implementation for MyAbstractClass and the runtime type of that instance is MyConcreteClass. For all intents and purposes object1 is treated by the compiler as if it is a MyAbstractClass instance. If you were to try to call the <code>sayHello()<\/code> method defined in MyConcreteClass you would get a compiler error. This method is not <strong>visible<\/strong> to the compiler through object1 because object1 is a MyAbstractClass reference. The only guarantee object1 provides is that it will have implementations for the methods defined in MyAbstractClass, any other methods provided by the runtime type are not visible.<\/p>\n<pre class=\"brush:java\">object1.sayHello(); \/\/ compiler error<\/pre>\n<p>As with interfaces we can provide different runtime types and use them through the same reference.<\/p>\n<p>Lets define a new abstract class<\/p>\n<pre class=\"brush:java\">public abstract class TwoMethodAbstractClass {\n\t\n\tpublic void oneMethod() {\n\t\tSystem.out.prinln(\"oneMethod is implemented in TwoMethodAbstractClass.\");\n\t}\n\n\tpublic abstract void twoMethod();\n}<\/pre>\n<p>It defines one implemented method an another abstract method.<\/p>\n<p>Let\u2019s extend it with a concrete class<\/p>\n<pre class=\"brush:java\">public class ConcreteClassA extends TwoMethodAbstractClass {\n\t\n\tpublic void twoMethod() {\n\t\tSystem.out.println(\"twoMethod is implemented in ConcreteClassA.\");\n}\n}<\/pre>\n<p>We can use it in a client just like before:<\/p>\n<pre class=\"brush:java\">TwoMethodAbstractClass myObject = new ConcreteClassA();\nmyObject.oneMethod();\nmyObject.twoMethod();<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre class=\"brush:bash\">oneMethod is implemented in TwoMethodAbstractClass.\ntwoMethod is implemented in ConcreteClassA.<\/pre>\n<p>Now let\u2019s make a different concrete class which extends TwoMethodClass:<\/p>\n<pre class=\"brush:java\">public class ConcreteClassB extends TwoMethodAbstractClass {\n\n\tpublic void twoMethod() {\n\t\tSystem.out.println(\"ConcreteClassB implements its own twoMethod.\");\n\t}\n}<\/pre>\n<p>And modify our code above:<\/p>\n<pre class=\"brush:java\">TwoMethodAbstractClass myObject = new ConcreteClassA();\nmyObject.oneMethod();\nmyObject.twoMethod();\nmyObject = new ConcreteClassB();\nmyObject.oneMethod();\nmyObject.twoMethod();\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre class=\"brush:bash\">oneMethod is implemented in TwoMethodAbstractClass.\ntwoMethod is implemented in ConcreteClassA.\noneMethod is implemented in TwoMethodAbstractClass.\nConcreteClassB implements its own twoMethod.\n<\/pre>\n<p>We have used the same reference (myObject) to refer to instances of two different runtime types. When the runtime type of myObject is ConcreteClassA it uses the implementation of twoMethod from ConcreteClassA. When the runtime type of myObject is ConcreteClassB it uses the implementation of twoMethod from ConcreteClassB. In both cases the common implementation of oneMethod from TwoMethodAbstractClass is used.<\/p>\n<p>Abstract classes are used to define common behaviours while providing contracts or promises that other behaviours will be available from a concrete class later. This allows us to build object models where we can reuse common functionality and capture differing requirements in different concrete classes.<\/p>\n<h1><a name=\"example\"><\/a>4. A Worked Example &#8211; Payments System<\/h1>\n<p>We have been asked to build a payments system for a company. We know that the company has different types of employees that can be paid in different ways; salaried and with commission. The boss of the company understands that his needs will change and the system may be changed later to accommodate different types of entities which will receive payments.<\/p>\n<h2><a name=\"payee\"><\/a>4.1. The Payee Interface<\/h2>\n<p>Let\u2019s start by considering the employees. They must receive payments, but we also know that later on we may need to have different entities also receive payments. Let\u2019s create an interface, Payee, which will define the sort of behaviour we\u2019d expect from entities which can receive payments.<\/p>\n<pre class=\"brush:java\">public interface Payee {\n\n\tString name();\n\n\tDouble grossPayment();\n\n\tInteger bankAccount();\n}<\/pre>\n<p>Here we have a Payee interface which guarantees three behaviours; the ability to provide a name for the Payee, the ability to provide a gross payment amount which should be paid and the ability to provide a bank account number where the funds should be deposited.<\/p>\n<h2><a name=\"system\"><\/a>4.2. The Payment System<\/h2>\n<p>Now that we have a Payee defined let\u2019s write some code that uses it. We\u2019ll create a PaymentSystem class which maintains a list of Payees and on demand will cycle through them and transfer the requested amount into the appropriate bank account.<\/p>\n<pre class=\"brush:java\">public class PaymentSystem {\n\n\tprivate List&lt;Payee&gt; payees;\n\n\tpublic PaymentSystem() {\n    \t\tpayees = new ArrayList&lt;&gt;();\n\t}\n\n\tpublic void addPayee(Payee payee) {\n    \t\tif (!payees.contains(payee)) {\n        \t\t\tpayees.add(payee);\n    \t\t}\n\t}\n\n\tpublic void processPayments() {\n    \t\tfor (Payee payee : payees) {\n        \t\t\tDouble grossPayment = payee.grossPayment();\n\n        \t\t\tSystem.out.println(\"Paying to \" + payee.name());\n        \t\t\tSystem.out.println(\"\\tGross\\t\" + grossPayment);\n        \t\t\tSystem.out.println(\"\\tTransferred to Account: \" + payee.bankAccount());\n    \t\t}\n\t}\n}<\/pre>\n<p>You can see that the PaymentSystem is totally <strong>agnostic<\/strong> as to the runtime types of the Payees, it doesn\u2019t care and doesn\u2019t have to care. It knows that no matter what the runtime type the Payee being process is guaranteed to implement <code>name()<\/code>, <code>grossPayment()<\/code> and <code>bankAccount()<\/code>. Given that knowledge it\u2019s simply a matter of executing a for loop across all the Payees and processing their payments using these methods.<\/p>\n<h2><a name=\"employee\"><\/a>4.3. The Employee Classes<\/h2>\n<p>We have been told by the boss that he has two different types of Employee &#8211; Salaried Employees and Commissioned Employees. Salaried Employees have a base salary which doesn\u2019t change while Commissioned Employees have a base salary and also can be given sales commissions for successful sales.<\/p>\n<h3>4.3.1 The SalaryEmployee Class<\/h3>\n<p>Let\u2019s start with a class for Salaried Employees. It should implement the Payee interface so it can be used by the Payment System.<\/p>\n<p>Let\u2019s represent our changes using class diagrams in addition to code. In class diagrams a dotted arrow means an \u2018implements\u2019 relationship and a solid arrow means an \u2018extends\u2019 relationship.<\/p>\n<h4>Class Diagram<\/h4>\n<p><figure id=\"attachment_27371\" aria-describedby=\"caption-attachment-27371\" style=\"width: 206px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/image001.png\"><img decoding=\"async\" class=\"wp-image-27371 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/image001.png\" alt=\"Figure 1 Abstraction in Java\" width=\"206\" height=\"231\"><\/a><figcaption id=\"caption-attachment-27371\" class=\"wp-caption-text\">Figure 1<\/figcaption><\/figure><\/p>\n<h4>Code<\/h4>\n<pre class=\"brush:java\">public class SalaryEmployee implements Payee {\n\n\tprivate String name;\n\tprivate Integer bankAccount;\n\tprotected Double grossWage;\n    \n\tpublic SalaryEmployee(String name, Integer bankAccount, Double grossWage) {\n    \t\tthis.name = name;\n    \t\tthis.bankAccount = bankAccount;\n    \t\tthis.grossWage = grossWage;\n\t}\n\n\tpublic Integer bankAccount() {\n    \t\treturn bankAccount;\n\t}\n    \n\tpublic String name() {\n    \t\treturn name;\n\t}\n    \n\tpublic Double grossPayment() {\n    \t\treturn grossWage;\n\t}\n}<\/pre>\n<h3>4.3.2 The CommissionEmployee Class<\/h3>\n<p>Now let\u2019s make a CommissionEmployee class. This class will be quite similar to the SalaryEmployee with the ability to pay commissions.<\/p>\n<h4>Class Diagram<\/h4>\n<p><figure id=\"attachment_27372\" aria-describedby=\"caption-attachment-27372\" style=\"width: 438px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/image003.png\"><img decoding=\"async\" class=\"wp-image-27372 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/image003.png\" alt=\"Figure 2 Abstraction in Java\" width=\"438\" height=\"232\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/image003.png 438w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/image003-300x158.png 300w\" sizes=\"(max-width: 438px) 100vw, 438px\" \/><\/a><figcaption id=\"caption-attachment-27372\" class=\"wp-caption-text\">Figure 2<\/figcaption><\/figure><\/p>\n<h4>Code<\/h4>\n<pre class=\"brush:java\">public class CommissionEmployee implements Payee {\n\n\tprivate String name;\n\tprivate Integer bankAccount;\n\tprotected Double grossWage;\n\tprivate Double grossCommission = 0.0;\n\n\tpublic CommissionEmployee(String name, Integer bankAccount, Double grossWage) {\n    \t\tthis.name = name;\n    \t\tthis.bankAccount = bankAccount;\n    \t\tthis.grossWage = grossWage;\n\t}\n\n\tpublic Integer bankAccount() {\n    \t\treturn bankAccount;\n\t}\n\n\tpublic String name() {\n    \t\treturn name;\n\t}\n\n\tpublic Double grossPayment() {\n    \t\treturn grossWage + doCurrentCommission();\n\t}\n\n\tprivate Double doCurrentCommission() {\n    \t\tDouble commission = grossCommission;\n    \t\tgrossCommission = 0.0;\n    \t\treturn commission;\n\t}\n\n\tpublic void giveCommission(Double amount) {\n    \t\tgrossCommission += amount;\n\t}\n}<\/pre>\n<p>As you can see a lot of the code is duplicated between SalaryEmployee and CommissionEmployee. In fact the only thing that\u2019s different is the calculation for grossPayment, which uses a commission value in CommissionEmployee. Some of the functionality is the same, and some is different. This looks a like a good candidate for an Abstract Class.<\/p>\n<h3>4.3.3 The Employee Abstract Class<\/h3>\n<p>Let\u2019s abstract the name and bank account functionality into an Employee abstract class. SalaryEmployee and CommissionEmployee can then extend this abstract class and provide different implementations for <code>grossPayment()<\/code>.<\/p>\n<h4>Class Diagram<\/h4>\n<p><figure id=\"attachment_27373\" aria-describedby=\"caption-attachment-27373\" style=\"width: 445px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/image005.png\"><img decoding=\"async\" class=\"wp-image-27373 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/image005.png\" alt=\"Figure 3 Abstraction in Java\" width=\"445\" height=\"328\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/image005.png 445w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/image005-300x221.png 300w\" sizes=\"(max-width: 445px) 100vw, 445px\" \/><\/a><figcaption id=\"caption-attachment-27373\" class=\"wp-caption-text\">Figure 3<\/figcaption><\/figure><\/p>\n<h4>Code<\/h4>\n<pre class=\"brush:java\">public abstract class Employee implements Payee {\n\n\tprivate String name;\n\tprivate Integer bankAccount;\n\tprotected Double grossWage;\n\n\tpublic Employee(String name, Integer bankAccount, Double grossWage) {\n    \t\tthis.name = name;\n    \t\tthis.bankAccount = bankAccount;\n    \t\tthis.grossWage = grossWage;\n\t}\n\n\tpublic String name() {\n    \t\treturn name;\n\t}\n\n\tpublic Integer bankAccount() {\n    \t\treturn bankAccount;\n\t}\n}<\/pre>\n<p>Note that Employee doesn\u2019t have to implement the grossPayment() method defined in Payee because Employee is abstract.<\/p>\n<p>Now let\u2019s rewrite the two Employee classes:<\/p>\n<pre class=\"brush:java\">public class SalaryEmployee extends Employee {\n\n\tpublic SalaryEmployee(String name, Integer bankAccount, Double grossWage) {\n    \t\tsuper(name, bankAccount, grossWage);\n\t}\n\n\tpublic Double grossPayment() {\n    \t\treturn grossWage;\n\t}\n}\n\npublic class CommissionEmployee extends Employee {\n\n\tprivate Double grossCommission = 0.0;\n\n\tpublic CommissionEmployee(String name, Integer bankAccount, Double grossWage) {\n    \t\tsuper(name, bankAccount, grossWage);\n\t}\n\n\tpublic Double grossPayment() {\n    \t\treturn grossWage + doCurrentCommission();\n\t}\n\n\tprivate Double doCurrentCommission() {\n    \t\tDouble commission = grossCommission;\n    \t\tgrossCommission = 0.0;\n    \t\treturn commission;\n\t}\n\n\tpublic void giveCommission(Double amount) {\n    \t\tgrossCommission += amount;\n\t}\n}<\/pre>\n<p>Much neater!<\/p>\n<h2><a name=\"the_application\"><\/a>4.4. The Application<\/h2>\n<p>Let\u2019s try using our new Employee types in an application. We\u2019ll create an application class that initializes the system by creating a Payment System, some Employees and simulating a week of work.<\/p>\n<h3>4.4.1 The PaymentApplication Class<\/h3>\n<p>The application class looks like this:<\/p>\n<pre class=\"brush:java\">public class PaymentApplication {\n\n\tpublic static void main(final String... args) {\n    \t\t\/\/ Initialization\n    \t\tPaymentSystem paymentSystem = new PaymentSystem();\n\n    \t\tCommissionEmployee johnSmith = new CommissionEmployee(\"John Smith\", 1111, 300.0);\n    \t\tpaymentSystem.addPayee(johnSmith);\n\n    \t\tCommissionEmployee paulJones = new CommissionEmployee(\"Paul Jones\", 2222, 350.0);\n    \t\tpaymentSystem.addPayee(paulJones);\n\n    \t\tSalaryEmployee maryBrown = new SalaryEmployee(\"Mary Brown\", 3333, 500.0);\n    \t\tpaymentSystem.addPayee(maryBrown);\n\n    \t\tSalaryEmployee susanWhite = new SalaryEmployee(\"Susan White\", 4444, 470.0);\n    \t\tpaymentSystem.addPayee(susanWhite);\n\n    \t\t\/\/ Simulate Week\n    \t\tjohnSmith.giveCommission(40.0);\n    \t\tjohnSmith.giveCommission(35.0);\n    \t\tjohnSmith.giveCommission(45.0);\n\n    \t\tpaulJones.giveCommission(45.0);\n    \t\tpaulJones.giveCommission(51.0);\n    \t\tpaulJones.giveCommission(23.0);\n    \t\tpaulJones.giveCommission(14.5);\n    \t\tpaulJones.giveCommission(57.3);\n\n    \t\t\/\/ Process Weekly Payment\n    \t\tpaymentSystem.processPayments();\n\t}<\/pre>\n<p>We create two commissioned employees and two salaried employees, each with their own names, base wages and bank account numbers. We load each of the employees into the Payment System we created. We then simulate a week by giving commissions to the two commissioned employees and then ask the Payment System to process all the payments for the week.<\/p>\n<p><strong>Output:<\/strong><\/p>\n<pre class=\"brush:bash\">Paying to John Smith\n    Gross    420.0\n    Transferred to Account: 1111\nPaying to Paul Jones\n    Gross    540.8\n    Transferred to Account: 2222\nPaying to Mary Brown\n    Gross    500.0\n    Transferred to Account: 3333\nPaying to Susan White\n    Gross    470.0\n    Transferred to Account: 4444\n<\/pre>\n<h2><a name=\"handling_bonuses\"><\/a>4.5. Handling Bonuses<\/h2>\n<p>The boss is very happy with the system so far, but he\u2019s told us that in order to motivate his employees he wants the ability to give them weekly percentage bonuses. He tells us that because Commissioned Employees are typically on a lower salary we should give them a bonus multiplier of 1.5x in order that their percentage bonus is bumped up. The bonus should be reflected in the gross payment of each employee.<\/p>\n<h3>4.5.1 The Employee Class for Bonuses<\/h3>\n<p>Let\u2019s add a field to employee to capture any bonuses that are given, a protected method to return and reset the bonus and an abstract method to give the bonus. The <code>doBonus()<\/code> method is protected so that it can be accessed by the concrete Employee classes. The giveBonus method is abstract because it will be implemented differently for Salaried and Commissioned Employees.<\/p>\n<pre class=\"brush:java\">public abstract class Employee implements Payee {\n\n\tprivate String name;\n\tprivate Integer bankAccount;\n\n\tprotected Double currentBonus;\n\tprotected Double grossWage;\n\n\tpublic Employee(String name, Integer bankAccount, Double grossWage) {\n    \t\tthis.name = name;\n    \t\tthis.bankAccount = bankAccount;\n    \t\tthis.grossWage = grossWage;\n    \t\tcurrentBonus = 0.0;\n\t}\n\n\tpublic String name() {\n    \t\treturn name;\n\t}\n\n\tpublic Integer bankAccount() {\n    \t\treturn bankAccount;\n\t}\n\n\tpublic abstract void giveBonus(Double percentage);\n\n\tprotected Double doCurrentBonus() {\n    \t\tDouble bonus = currentBonus;\n    \t\tcurrentBonus = 0.0;\n    \t\treturn bonus;\n\t}\n}<\/pre>\n<p><strong>Updates to SalaryEmployee:<\/strong><\/p>\n<pre class=\"brush:java\">public class SalaryEmployee extends Employee {\n\n\tpublic SalaryEmployee(String name, Integer bankAccount, Double grossWage) {\n    \t\tsuper(name, bankAccount, grossWage);\n\t}\n\n\tpublic void giveBonus(Double percentage) {\n    \t\tcurrentBonus += grossWage * (percentage\/100.0);\n\t}\n\n\tpublic Double grossPayment() {\n    \t\treturn grossWage + doCurrentBonus();\n\t}\n}\n<\/pre>\n<p><strong>Updates to CommissionEmployee:<\/strong><\/p>\n<pre class=\"brush:java\">public class CommissionEmployee extends Employee {\n\n\tprivate static final Double bonusMultiplier = 1.5;\n\n\tprivate Double grossCommission = 0.0;\n\n\tpublic CommissionEmployee(String name, Integer bankAccount, Double grossWage) {\n    \t\tsuper(name, bankAccount, grossWage);\n\t}\n\n\tpublic void giveBonus(Double percentage) {\n    \t\tcurrentBonus += grossWage * (percentage\/100.0) * bonusMultiplier;\n\t}\n\n\tpublic Double grossPayment() {\n    \t\treturn grossWage + doCurrentBonus() + doCurrentCommission();\n\t}\n\n\tprivate Double doCurrentCommission() {\n    \t\tDouble commission = grossCommission;\n    \t\tgrossCommission = 0.0;\n    \t\treturn commission;\n\t}\n\n\tpublic void giveCommission(Double amount) {\n    \t\tgrossCommission += amount;\n\t}\n}\n<\/pre>\n<p>We can see that both classes implement giveBonus() differently &#8211; CommissionEmployee uses the bonus multiplier. We can also see that both classes use the protected doCurrentBonus() method defined in Employee when working out the gross payment.<\/p>\n<p>Let\u2019s update our application to simulate paying some weekly bonuses to our Employees:<\/p>\n<pre class=\"brush:java\">public class PaymentApplication {\n\n\tpublic static void main(final String... args) {\n    \t\t\/\/ Initialization\n    \t\tPaymentSystem paymentSystem = new PaymentSystemV1();\n\n    \t\tCommissionEmployee johnSmith = new CommissionEmployee(\"John Smith\", 1111, 300.0);\n    \t\tpaymentSystem.addPayee(johnSmith);\n\n    \t\tCommissionEmployee paulJones = new CommissionEmployee(\"Paul Jones\", 2222, 350.0);\n    \t\tpaymentSystem.addPayee(paulJones);\n\n    \t\tSalaryEmployee maryBrown = new SalaryEmployee(\"Mary Brown\", 3333, 500.0);\n    \t\tpaymentSystem.addPayee(maryBrown);\n\n    \t\tSalaryEmployee susanWhite = new SalaryEmployee(\"Susan White\", 4444, 470.0);\n    \t\tpaymentSystem.addPayee(susanWhite);\n\n    \t\t\/\/ Simulate Week\n    \t\tjohnSmith.giveCommission(40.0);\n    \tjohnSmith.giveCommission(35.0);\n    \tjohnSmith.giveCommission(45.0);\n    \tjohnSmith.giveBonus(5.0);\n\n    \tpaulJones.giveCommission(45.0);\n    \tpaulJones.giveCommission(51.0);\n    \tpaulJones.giveCommission(23.0);\n    \tpaulJones.giveCommission(14.5);\n    \tpaulJones.giveCommission(57.3);\n    \tpaulJones.giveBonus(6.5);\n\n    \tmaryBrown.giveBonus(3.0);\n\n    \tsusanWhite.giveBonus(7.5);\n\n    \t\t\/\/ Process Weekly Payment\n    \t\tpaymentSystem.processPayments();\n\t}\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre class=\"brush:bash\">Paying to John Smith\n    Gross    442.5\n    Transferred to Account: 1111\nPaying to Paul Jones\n    Gross    574.925\n    Transferred to Account: 2222\nPaying to Mary Brown\n    Gross    515.0\n    Transferred to Account: 3333\nPaying to Susan White\n    Gross    505.25\n    Transferred to Account: 4444\n<\/pre>\n<p>The Gross amounts now reflect the bonuses paid to the employees.<\/p>\n<h2><a name=\"contracting_companies\"><\/a>4.6. Contracting Companies<\/h2>\n<p>The boss is delighted with the Payment System, however he\u2019s thought of someone else he needs to pay. From time to time he will engage the services of a contracting company. Obviously these companies don\u2019t have wages and aren\u2019t paid bonuses. They can get several one off payments and when processed by the payment system should be paid all cumulative payments and have their balance cleared.<\/p>\n<h3>4.6.1. The ContractingCompany Class<\/h3>\n<p>The ContractingCompany class should implement Payee so it can be used by the Payments System. It should have a method for paying for services which will be tracked by a cumulative total and used for payments.<\/p>\n<h4>Class Diagram<\/h4>\n<p><figure id=\"attachment_27374\" aria-describedby=\"caption-attachment-27374\" style=\"width: 573px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/image007.png\"><img decoding=\"async\" class=\"wp-image-27374 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/image007.png\" alt=\"Figure 4 Abstraction in Java\" width=\"573\" height=\"326\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/image007.png 573w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/image007-300x170.png 300w\" sizes=\"(max-width: 573px) 100vw, 573px\" \/><\/a><figcaption id=\"caption-attachment-27374\" class=\"wp-caption-text\">Figure 4<\/figcaption><\/figure><\/p>\n<h4>Code<\/h4>\n<pre class=\"brush:java\">public class ContractingCompany implements Payee {\n\n\tprivate String name;\n\tprivate Integer bankAccount;\n\tprivate Double currentBalance;\n\n\tpublic ContractingCompany(String name, Integer bankAccount) {\n    \t\tthis.name = name;\n    \t\tthis.bankAccount = bankAccount;\n    \t\tcurrentBalance = 0.0;\n\t}\n\n\tpublic String name() {\n    \t\treturn name;\n\t}\n\n\tpublic Double grossPayment() {\n    \t\treturn doPayment();\n\t}\n\n\tprivate Double doPayment() {\n    \t\tDouble balance = currentBalance;\n    \t\tcurrentBalance = 0.0;\n    \t\treturn balance;\n\t}\n\n\tpublic Integer bankAccount() {\n    \t\treturn bankAccount;\n\t}\n\n\tpublic void payForServices(Double amount) {\n    \t\tcurrentBalance += amount;\n\t}\n}<\/pre>\n<p>Lets now add a couple of contracting companies to our Payment Application and simulate some payments to them:<\/p>\n<pre class=\"brush:java\">public class PaymentApplication {\n\n\tpublic static void main(final String... args) {\n    \t\/\/ Initialization\n    \tPaymentSystem paymentSystem = new PaymentSystemV1();\n\n    \tCommissionEmployee johnSmith = new CommissionEmployee(\"John Smith\", 1111, 300.0, 100.0);\n    \tpaymentSystem.addPayee(johnSmith);\n\n    \tCommissionEmployee paulJones = new CommissionEmployee(\"Paul Jones\", 2222, 350.0, 125.0);\n    \tpaymentSystem.addPayee(paulJones);\n\n    \tSalaryEmployee maryBrown = new SalaryEmployee(\"Mary Brown\", 3333, 500.0, 110.0);\n    \tpaymentSystem.addPayee(maryBrown);\n\n    \tSalaryEmployee susanWhite = new SalaryEmployee(\"Susan White\", 4444, 470.0, 130.0);\n    \tpaymentSystem.addPayee(susanWhite);\n\n    \tContractingCompany acmeInc = new ContractingCompany(\"Acme Inc\", 5555);\n    \tpaymentSystem.addPayee(acmeInc);\n\n    \tContractingCompany javaCodeGeeks = new ContractingCompany(\"javacodegeeks.com\", 6666);\n    \tpaymentSystem.addPayee(javaCodeGeeks);\n\n    \t\/\/ Simulate Week\n    \tjohnSmith.giveCommission(40.0);\n    \tjohnSmith.giveCommission(35.0);\n    \tjohnSmith.giveCommission(45.0);\n    \tjohnSmith.giveBonus(5.0);\n\n    \tpaulJones.giveCommission(45.0);\n    \tpaulJones.giveCommission(51.0);\n    \tpaulJones.giveCommission(23.0);\n    \tpaulJones.giveCommission(14.5);\n    \tpaulJones.giveCommission(57.3);\n    \tpaulJones.giveBonus(6.5);\n\n    \tmaryBrown.giveBonus(3.0);\n\n    \tsusanWhite.giveBonus(7.5);\n\n    \tacmeInc.payForServices(100.0);\n    \tacmeInc.payForServices(250.0);\n    \tacmeInc.payForServices(300.0);\n\n    \tjavaCodeGeeks.payForServices(400.0);\n    \tjavaCodeGeeks.payForServices(250.0);\n\n    \t\/\/ Process Weekly Payment\n    \tpaymentSystem.processPayments();\n\t}\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre class=\"brush:bash\">Paying to John Smith\n    Gross    442.5\n    Transferred to Account: 1111\nPaying to Paul Jones\n    Gross    574.925\n    Transferred to Account: 2222\nPaying to Mary Brown\n    Gross    515.0\n    Transferred to Account: 3333\nPaying to Susan White\n    Gross    505.25\n    Transferred to Account: 4444\nPaying to Acme Inc\n    Gross    650.0\n    Transferred to Account: 5555\nPaying to javacodegeeks.com\n    Gross    650.0\n    Transferred to Account: 6666\n<\/pre>\n<p>We have now successfully added a brand new type of Payee to the system without having to change one single line of code in the PaymentSystem class which handles Payees. This is the power of abstraction.<br \/>\n[ulp id=&#8217;Lcy8uILhlHKhh3Oa&#8217;]<br \/>\n&nbsp;<\/p>\n<h2><a name=\"taxation\"><\/a>4.7. Advanced Functionality: Taxation<\/h2>\n<p>The boss is over the moon with the Payment System, however the taxman has sent him a letter telling him that he has to incorporate some sort of tax withholding into the system or he\u2019ll be in big trouble. There should be a global tax rate for the system and each employee should have a personal tax free allowance. The tax should only be collected on any payments made to an employee over and above the tax free allowance. The employee should then only be paid the net amount of payment due to them. Contracting Companies are responsible for paying their own tax so the system should not withhold tax from them.<\/p>\n<p>In order to handle taxation we\u2019ll need to create a new, special, type of Payee which is taxable and can provide a tax free allowance figure.<\/p>\n<p>In Java we can extend interfaces. This let\u2019s us add behaviour definitions without modifying our original interface. All of the behaviour defined in the original interface will be automatically carried into the new interface.<\/p>\n<h3>4.7.1. The TaxablePayee Interface<\/h3>\n<p>We\u2019ll extend Payee to create a new TaxablePayee interface, we\u2019ll then have Employee implement that interface, while letting ContractingCompany remain as a regular, untaxed, Payee.<\/p>\n<h4>Class Diagram<\/h4>\n<p><figure id=\"attachment_27375\" aria-describedby=\"caption-attachment-27375\" style=\"width: 576px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/image009.png\"><img decoding=\"async\" class=\"wp-image-27375 size-full\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/image009.png\" alt=\"Figure 5 Abstraction in Java\" width=\"576\" height=\"439\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/image009.png 576w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/image009-300x228.png 300w\" sizes=\"(max-width: 576px) 100vw, 576px\" \/><\/a><figcaption id=\"caption-attachment-27375\" class=\"wp-caption-text\">Figure 5<\/figcaption><\/figure><\/p>\n<h4>Code<\/h4>\n<pre class=\"brush:java\">public interface TaxablePayee extends Payee {\n\n\tpublic Double allowance();\n\n}\n<\/pre>\n<p>Here we see that Payee is extended and an additional method is defined &#8211; <code>allowance()<\/code> which returns the tax free allowance of the TaxablePayee.<\/p>\n<p>We\u2019ll now need to update Employee to implement TaxablePayee and we will see that this will have a knock on effect on both concrete Employee classes.<\/p>\n<pre class=\"brush:java\">public abstract class Employee implements TaxablePayee {\n\n\tprivate String name;\n\tprivate Integer bankAccount;\n\tprivate Double allowance;\n\n\tprotected Double currentBonus;\n\tprotected Double grossWage;\n\n\tpublic Employee(String name, Integer bankAccount, Double grossWage, Double allowance) {\n    \tthis.name = name;\n    \tthis.bankAccount = bankAccount;\n    \tthis.grossWage = grossWage;\n    \tthis.allowance = allowance;\n    \tcurrentBonus = 0.0;\n\t}\n\n\tpublic String name() {\n    \treturn name;\n\t}\n\n\tpublic Integer bankAccount() {\n    \t\treturn bankAccount;\n\t}\n\n\tpublic Double allowance() {\n    \t\treturn allowance;\n\t}\n\n\tpublic abstract void giveBonus(Double percentage);\n\n\tprotected Double doCurrentBonus() {\n    \t\tDouble bonus = currentBonus;\n    \t\tcurrentBonus = 0.0;\n    \t\treturn bonus;\n\t}\n\n}<\/pre>\n<p>We have had to change the constructor of Employee which implies that the constructors of our two abstract classes will also need to change.<\/p>\n<pre class=\"brush:java\">public class SalaryEmployee extends Employee {\n\n\tpublic SalaryEmployee(String name, Integer bankAccount, Double grossWage, Double allowance) {\n    \t\tsuper(name, bankAccount, grossWage, allowance);\n\t}\n\n\t@Override\n\tpublic void giveBonus(Double percentage) {\n    \t\tcurrentBonus += grossWage * (percentage\/100.0);\n\t}\n\n\t@Override\n\tpublic Double grossPayment() {\n    \t\treturn grossWage + doCurrentBonus();\n\t}\n}\n<\/pre>\n<p><strong>CommissionEmployee:<\/strong><\/p>\n<pre class=\"brush:java\">public class CommissionEmployee extends Employee {\n\n\tprivate static final Double bonusMultiplier = 1.5;\n\n\tprivate Double grossCommission = 0.0;\n\n\tpublic CommissionEmployee(String name, Integer bankAccount, Double grossWage, Double allowance) {\n    \t\tsuper(name, bankAccount, grossWage, allowance);\n\t}\n\n\t@Override\n\tpublic void giveBonus(Double percentage) {\n    \t\tcurrentBonus += grossWage * (percentage\/100.0) * bonusMultiplier;\n\t}\n\n\t@Override\n\tpublic Double grossPayment() {\n    \t\treturn grossWage + doCurrentBonus() + doCurrentCommission();\n\t}\n\n\tprivate Double doCurrentCommission() {\n    \t\tDouble commission = grossCommission;\n    \t\tgrossCommission = 0.0;\n    \t\treturn commission;\n\t}\n\n\tpublic void giveCommission(Double amount) {\n    \t\tgrossCommission += amount;\n\t}\n}\n<\/pre>\n<h3>4.7.1. Taxation changes in PaymentSystem<\/h3>\n<p>We now need to update PaymentSystem to withhold tax and to do this we\u2019ll need some way of determining if a given Payee is a TaxablePayee or a regular Payee. We can take advantage of a Java keyword called <strong>instanceof<\/strong> to do this.<\/p>\n<p>Instanceof lets us check to see if a given reference variable\u2019s runtime type matches a test type. It returns a boolean and can be called like so: if (object1 instanceof MyClass). This will return true if object1\u2019s runtime type is MyClass <em>or a subclass or implementing class (if MyClass is an interface)<\/em> of MyClass. This means we can test anywhere along the inheritance tree making it a very powerful tool. We can use this tool to determine if a given Payee is an instance of a TaxablePayee and take appropriate measures based on that knowledge.<\/p>\n<p>We now update the PaymentSystem as follows:<\/p>\n<pre class=\"brush:java\">public class PaymentSystem {\n\n\tprivate List&lt;Payee&gt; payees;\n\tprivate Double taxRate = 0.2;\n\n\tpublic PaymentSystem() {\n    \t\tpayees = new ArrayList&lt;&gt;();\n\t}\n\n\tpublic void addPayee(Payee payee) {\n    \t\tif (!payees.contains(payee)) {\n        \t\tpayees.add(payee);\n    \t\t}\n\t}\n\n\tpublic void processPayments() {\n    \t\tfor (Payee payee : payees) {\n        \t\t\tDouble grossPayment = payee.grossPayment();\n        \t\t\tDouble tax = 0.0;\n        \t\t\tif (payee instanceof TaxablePayee) {\n            \t\t\tDouble taxableIncome = grossPayment - ((TaxablePayee)payee).allowance();\n            \t\t\ttax = taxableIncome * taxRate;\n        \t\t\t}\n        \t\t\tDouble netPayment = grossPayment - tax;\n\n        \t\tSystem.out.println(\"Paying to \" + payee.name());\n        \t\tSystem.out.println(\"\\tGross\\t\" + grossPayment);\n        \t\tSystem.out.println(\"\\tTax\\t\\t-\" + tax);\n        \t\tSystem.out.println(\"\\tNet\\t\\t\" + netPayment);\n        \t\tSystem.out.println(\"\\tTransferred to Account: \" + payee.bankAccount());\n    \t\t}\n\t}\n}\n\n<\/pre>\n<p>The new code first checks if the Payee being processed is an instance of TaxablePayee, if it is it then does a <strong>cast<\/strong> on the Payee to treat it as a reference to a TaxablePayee for the purposes of accessing the <code>allowance()<\/code> method defined in TaxablePayee. Remember; if the reference stayed as a Payee the <code>allowance()<\/code> method would not be visible to the PaymentSystem because it is defined in TaxablePayee, not Payee. The cast is safe here because we have already confirmed that the Payee is an instance of TaxablePayee. Now that PaymentSystem has the allowance it can work out the taxable amount and the tax to be withheld based on the global tax rate of 20%.<\/p>\n<p>If the Payee is not a TaxablePayee the system continues to process them as normal, not doing anything related to tax processing.<\/p>\n<p>Let\u2019s update our application class to give our employees different tax free allowances and execute the application again:<\/p>\n<pre class=\"brush:java\">public class PaymentApplication {\n\n\tpublic static void main(final String... args) {\n    \t\/\/ Initialization\n    \tPaymentSystem paymentSystem = new PaymentSystemV1();\n\n    \tCommissionEmployee johnSmith = new CommissionEmployee(\"John Smith\", 1111, 300.0, 100.0);\n    \tpaymentSystem.addPayee(johnSmith);\n\n    \tCommissionEmployee paulJones = new CommissionEmployee(\"Paul Jones\", 2222, 350.0, 125.0);\n    \tpaymentSystem.addPayee(paulJones);\n\n    \tSalaryEmployee maryBrown = new SalaryEmployee(\"Mary Brown\", 3333, 500.0, 110.0);\n    \tpaymentSystem.addPayee(maryBrown);\n\n    \tSalaryEmployee susanWhite = new SalaryEmployee(\"Susan White\", 4444, 470.0, 130.0);\n    \tpaymentSystem.addPayee(susanWhite);\n\n    \tContractingCompany acmeInc = new ContractingCompany(\"Acme Inc\", 5555);\n    \tpaymentSystem.addPayee(acmeInc);\n\n    \tContractingCompany javaCodeGeeks = new ContractingCompany(\"javacodegeeks.com\", 6666);\n    \tpaymentSystem.addPayee(javaCodeGeeks);\n\n    \t\/\/ Simulate Week\n    \tjohnSmith.giveCommission(40.0);\n    \tjohnSmith.giveCommission(35.0);\n    \tjohnSmith.giveCommission(45.0);\n    \tjohnSmith.giveBonus(5.0);\n\n    \tpaulJones.giveCommission(45.0);\n    \tpaulJones.giveCommission(51.0);\n    \tpaulJones.giveCommission(23.0);\n    \tpaulJones.giveCommission(14.5);\n    \tpaulJones.giveCommission(57.3);\n    \tpaulJones.giveBonus(6.5);\n\n    \tmaryBrown.giveBonus(3.0);\n\n    \tsusanWhite.giveBonus(7.5);\n\n    \tacmeInc.payForServices(100.0);\n    \tacmeInc.payForServices(250.0);\n    \tacmeInc.payForServices(300.0);\n\n    \tjavaCodeGeeks.payForServices(400.0);\n    \tjavaCodeGeeks.payForServices(250.0);\n\n    \t\/\/ Process Weekly Payment\n    \tpaymentSystem.processPayments();\n\t}\n}\n\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre class=\"brush:bash\">Paying to John Smith\n    Gross    \t442.5\n    Tax\t\t-68.5\n    Net   \t 374.0\n    Transferred to Account: 1111\nPaying to Paul Jones\n    Gross    \t574.925\n    Tax   \t -89.985\n    Net   \t 484.93999999999994\n    Transferred to Account: 2222\nPaying to Mary Brown\n    Gross    \t515.0\n    Tax   \t -81.0\n    Net   \t 434.0\n    Transferred to Account: 3333\nPaying to Susan White\n    Gross    \t505.25\n    Tax   \t -75.05\n    Net   \t 430.2\n    Transferred to Account: 4444\nPaying to Acme Inc\n    Gross    \t650.0\n    Tax   \t -0.0\n    Net   \t 650.0\n    Transferred to Account: 5555\nPaying to javacodegeeks.com\n    Gross    \t650.0\n    Tax   \t -0.0\n    Net   \t 650.0\n    Transferred to Account: 6666\n<\/pre>\n<p>As you can see tax is calculated and withheld for Employees, while Contracting Companies continue to pay no tax. The boss couldn\u2019t be happier with the system and is going to gift us an all expenses paid vacation for keeping him out of jail!<\/p>\n<h1><a name=\"Conclusion\"><\/a>5. Conclusion<\/h1>\n<p>Abstraction is a very powerful tool in Java when used in the correct way. It opens up many possibilities for advanced java use and for building complex, extensible and maintainable software. We have just scratched the surface of what abstraction can do for us and hopefully built a foundation for learning about the different ways abstraction can be used in more detail.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>EDITORIAL NOTE: In this post, we feature a comprehensive Abstraction in Java Tutorial. Abstraction occurs during class level design, with the objective of hiding the implementation complexity of how the the features offered by an API \/ design \/ system were implemented, in a sense simplifying the &#8216;interface&#8217; to access the underlying implementation. This process &hellip;<\/p>\n","protected":false},"author":582,"featured_media":148,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[969,1039],"class_list":["post-27331","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-core-java","tag-abstraction","tag-ultimate"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Abstraction in Java - The ULTIMATE Tutorial (PDF Download)<\/title>\n<meta name=\"description\" content=\"Check out our Abstraction in Java Tutorial where you can learn about interfaces &amp; more. You can download our FREE Abstraction in Java Ultimate Guide!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2014\/07\/abstraction-in-java.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Abstraction in Java - The ULTIMATE Tutorial (PDF Download)\" \/>\n<meta property=\"og:description\" content=\"Check out our Abstraction in Java Tutorial where you can learn about interfaces &amp; more. You can download our FREE Abstraction in Java Ultimate Guide!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2014\/07\/abstraction-in-java.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2014-07-15T08:09:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-05T13:45:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Hugh Hamill\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Hugh Hamill\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"18 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/abstraction-in-java.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/abstraction-in-java.html\"},\"author\":{\"name\":\"Hugh Hamill\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/16859fadb54e0a7d918890100afa9c3e\"},\"headline\":\"Abstraction in Java &#8211; The ULTIMATE Tutorial (PDF Download)\",\"datePublished\":\"2014-07-15T08:09:10+00:00\",\"dateModified\":\"2023-12-05T13:45:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/abstraction-in-java.html\"},\"wordCount\":3901,\"commentCount\":29,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/abstraction-in-java.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"keywords\":[\"Abstraction\",\"Ultimate\"],\"articleSection\":[\"Core Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/abstraction-in-java.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/abstraction-in-java.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/abstraction-in-java.html\",\"name\":\"Abstraction in Java - The ULTIMATE Tutorial (PDF Download)\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/abstraction-in-java.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/abstraction-in-java.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"datePublished\":\"2014-07-15T08:09:10+00:00\",\"dateModified\":\"2023-12-05T13:45:13+00:00\",\"description\":\"Check out our Abstraction in Java Tutorial where you can learn about interfaces & more. You can download our FREE Abstraction in Java Ultimate Guide!\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/abstraction-in-java.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/abstraction-in-java.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/abstraction-in-java.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/java-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/07\\\/abstraction-in-java.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/core-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Abstraction in Java &#8211; The ULTIMATE Tutorial (PDF Download)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/16859fadb54e0a7d918890100afa9c3e\",\"name\":\"Hugh Hamill\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4bd03b43df8bac67e2fcb36550d4579d327760fd1b8a141f850e9a100e205df1?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4bd03b43df8bac67e2fcb36550d4579d327760fd1b8a141f850e9a100e205df1?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4bd03b43df8bac67e2fcb36550d4579d327760fd1b8a141f850e9a100e205df1?s=96&d=mm&r=g\",\"caption\":\"Hugh Hamill\"},\"description\":\"Hugh is a Senior Software Engineer and Certified Scrum Master based in Galway, Ireland. He achieved his B.Sc. in Applied Computing from Waterford Institute of Technology in 2002 and has been working in industry since then. He has worked for a several large blue chip software companies listed on both the NASDAQ and NYSE.\",\"sameAs\":[\"http:\\\/\\\/www.doubleh.ie\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/hugh-hamill\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Abstraction in Java - The ULTIMATE Tutorial (PDF Download)","description":"Check out our Abstraction in Java Tutorial where you can learn about interfaces & more. You can download our FREE Abstraction in Java Ultimate Guide!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2014\/07\/abstraction-in-java.html","og_locale":"en_US","og_type":"article","og_title":"Abstraction in Java - The ULTIMATE Tutorial (PDF Download)","og_description":"Check out our Abstraction in Java Tutorial where you can learn about interfaces & more. You can download our FREE Abstraction in Java Ultimate Guide!","og_url":"https:\/\/www.javacodegeeks.com\/2014\/07\/abstraction-in-java.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2014-07-15T08:09:10+00:00","article_modified_time":"2023-12-05T13:45:13+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","type":"image\/jpeg"}],"author":"Hugh Hamill","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Hugh Hamill","Est. reading time":"18 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2014\/07\/abstraction-in-java.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/07\/abstraction-in-java.html"},"author":{"name":"Hugh Hamill","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/16859fadb54e0a7d918890100afa9c3e"},"headline":"Abstraction in Java &#8211; The ULTIMATE Tutorial (PDF Download)","datePublished":"2014-07-15T08:09:10+00:00","dateModified":"2023-12-05T13:45:13+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/07\/abstraction-in-java.html"},"wordCount":3901,"commentCount":29,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/07\/abstraction-in-java.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","keywords":["Abstraction","Ultimate"],"articleSection":["Core Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2014\/07\/abstraction-in-java.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2014\/07\/abstraction-in-java.html","url":"https:\/\/www.javacodegeeks.com\/2014\/07\/abstraction-in-java.html","name":"Abstraction in Java - The ULTIMATE Tutorial (PDF Download)","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/07\/abstraction-in-java.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/07\/abstraction-in-java.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","datePublished":"2014-07-15T08:09:10+00:00","dateModified":"2023-12-05T13:45:13+00:00","description":"Check out our Abstraction in Java Tutorial where you can learn about interfaces & more. You can download our FREE Abstraction in Java Ultimate Guide!","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/07\/abstraction-in-java.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2014\/07\/abstraction-in-java.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2014\/07\/abstraction-in-java.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/java-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2014\/07\/abstraction-in-java.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/core-java"},{"@type":"ListItem","position":4,"name":"Abstraction in Java &#8211; The ULTIMATE Tutorial (PDF Download)"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/16859fadb54e0a7d918890100afa9c3e","name":"Hugh Hamill","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4bd03b43df8bac67e2fcb36550d4579d327760fd1b8a141f850e9a100e205df1?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4bd03b43df8bac67e2fcb36550d4579d327760fd1b8a141f850e9a100e205df1?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4bd03b43df8bac67e2fcb36550d4579d327760fd1b8a141f850e9a100e205df1?s=96&d=mm&r=g","caption":"Hugh Hamill"},"description":"Hugh is a Senior Software Engineer and Certified Scrum Master based in Galway, Ireland. He achieved his B.Sc. in Applied Computing from Waterford Institute of Technology in 2002 and has been working in industry since then. He has worked for a several large blue chip software companies listed on both the NASDAQ and NYSE.","sameAs":["http:\/\/www.doubleh.ie"],"url":"https:\/\/www.javacodegeeks.com\/author\/hugh-hamill"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/27331","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/582"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=27331"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/27331\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/148"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=27331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=27331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=27331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}