<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Hanno Van Der Walt on Medium]]></title>
        <description><![CDATA[Stories by Hanno Van Der Walt on Medium]]></description>
        <link>https://medium.com/@hannovdw1998?source=rss-f1bcc03cfa16------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*IuWBdsHG8pAGVo67dVNYOA.jpeg</url>
            <title>Stories by Hanno Van Der Walt on Medium</title>
            <link>https://medium.com/@hannovdw1998?source=rss-f1bcc03cfa16------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 03:03:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hannovdw1998/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Interface vs Abstract Class]]></title>
            <link>https://medium.com/@hannovdw1998/interface-vs-abstract-class-1cb84f5fae1b?source=rss-f1bcc03cfa16------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cb84f5fae1b</guid>
            <dc:creator><![CDATA[Hanno Van Der Walt]]></dc:creator>
            <pubDate>Fri, 10 Feb 2023 07:16:14 GMT</pubDate>
            <atom:updated>2023-02-10T07:16:14.850Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DF_GIXcg_b9U3MjKOcKnTw.jpeg" /></figure><p>In this article, we will be looking at the difference between an interface and an abstract class. It is essential for all software developers to know the differences so that they can effectively design and build applications. Lets look at the definitions as well as some practical examples to understand the differences.</p><h3>Interfaces</h3><p>Let us start by looking at the interface. An interface is a contract or a “blueprint”. It allows you to define abstract methods which is method signatures with no body. Interfaces are not allowed to contain any instance variables, but are allowed to have constants. A class can implement multiple interfaces and should implement all the functions that was declared in the interface. Interfaces does not make use of <a href="https://medium.com/@hannovdw1998/public-vs-private-java-aa1d03c4d52c">access modifiers</a> and defaults to public. Interfaces cannot be instantiated directly and must be implemented by another class. An interface cannot contain any constructors.</p><h3>When to use an Interface</h3><p>Interfaces should be used when the only common thing between the implementing classes is the method signature. Each implementing class will have its own implementation of the method. Remember that an interface cannot implement data fields like constructors and variables. Also note that a class can implement multiple interfaces. A useful way of determining if a action is appropriate for a interface is to use the “is able to” rule. For example a dog “is able to” communicate or a beetle “is able to” feed.</p><h3>Abstract Classes</h3><p>Abstract classes allows you to have functionality within your classes, like methods with bodies, this methods are called concrete methods. You can also add abstract methods to an abstract class and give them functionality in the extending class. Make sure to provide implementations in the class that extends the abstract class’s abstract methods. Similar to Interfaces, abstract classes cant be instantiated directly and a class can only extend a single abstract class. An abstract class can contain constructors, variables and concrete classes and can have <a href="https://medium.com/@hannovdw1998/public-vs-private-java-aa1d03c4d52c">access modifiers</a>.</p><h3>When to use an Abstract Class</h3><p>Abstract classes should be used when there is a common functionality between the implementing classes. Abstract classes allows for re use of code, eliminating the use to re-write repetitive code. Abstract classes also serves abstraction using abstract functions. Abstract classes can implement data fields like variables and constructors to inject services into the abstract class etc. A useful way of determining if a action is appropriate for an abstract class is to use the “is a” rule. For example a dog “is a” mammal or a bee “is a” insect.</p><h3>Practical Java example</h3><p>Lets start by creating a abstract class called Mammal.</p><p>It is important to note the following about the abstract class:</p><ul><li>The abstract class is able to contain a constructor. It is also allowed to contain other variables and constants.</li><li>The giveBirth() function contains a body (concrete method). All mammals gives birth in the same way (live birth) so it is appropriate to put it as a concrete method in an abstract class.</li><li>The abstract class contains an abstract method called clean() and we can implement it in the class that extends it. Each mammal will get cleaned in a unique way.</li></ul><pre>public abstract class Mammal {<br><br>    Mammal(){<br>        System.out.println(&quot;Mammal constructor&quot;);<br>    }<br><br>    public void giveBirth(){<br>        System.out.println(&quot;I am a mammal and I give live birth.&quot;);<br>    }<br><br>    public abstract void clean();<br><br>}</pre><p>Next lets make some interfaces that we can implement later. Lets make a Communicate and a Feed Interface. Note the following about the interfaces:</p><ul><li>Both the sayHello() and eat() methods are not allowed to have bodies.</li><li>It is allowed to have a static final constant called message.</li><li>It is not allowed to have any constructors.</li></ul><pre>public interface Comunicate {<br><br>    static final String message = &quot;Hello&quot;;<br><br>    void sayHello();<br><br>}</pre><pre>public interface Feed {<br><br>    void eat();<br><br>}</pre><p>Next let us make two classes called Dog and Bear. Note the following important points:</p><ul><li>both of these are mammals and the “is a” rule applies to them. A bear “is a” mammal and a dog “is a” mammal, so it is appropriate to extend the Mammal abstract class.</li><li>Note that we implemented both the Communicate and Feed Interfaces. Using the “is able to” rule, we can see that a Dog “is able to” communicate and a Bear “is able to” feed.</li><li>We also had to implement all the abstract methods that was declared in the Feed and Communicate interfaces. Because bears and dogs communicate and feed differently, it is appropriate to add the abstract sayHello() and eat() methods in an interface and implement it in the child classes.</li><li>Note that if we had a class called bee or butterfly, we can also implement the feed and communicate interfaces and have their own unique implementations. Extending the Mammal abstract class from a butterfly class would not make much sense because a butterfly cant give live birth.</li><li>We can extend only one abstract class (mammal)</li><li>We can implement multiple interfaces (Communicate, Feed)</li><li>Abstract methods like the clean() method (methods with no bodies) can also be declared in an abstract class and be implemented in the extending class.</li></ul><pre>public class Dog extends Mammal implements Comunicate, Feed {<br><br>    @Override<br>    public void sayHello() {<br><br>        System.out.println(message + &quot; in Dog language = Woof Woof.&quot;);<br><br>    }<br><br>    @Override<br>    public void eat() {<br>        System.out.println(&quot;I am a dog and eat dog food.&quot;);<br>    }<br><br>    @Override<br>    public void clean() {<br>        System.out.println(&quot;I make my owner clean me&quot;);<br>    }<br>}</pre><pre>public class Bear extends Mammal implements Comunicate, Feed{<br><br>    @Override<br>    public void sayHello() {<br><br>        System.out.println(message + &quot; in Bear language = Roarrr.&quot;);<br><br>    }<br><br>    @Override<br>    public void eat() {<br>        System.out.println(&quot;I am a Bear and i eat deer meat.&quot;);<br>    }<br><br>    @Override<br>    public void clean() {<br>        System.out.println(&quot;I bathe myself&quot;);<br>    }<br>}</pre><p>Create the main method and create a Dog and Bear object. We can call the functions we created in the interfaces and abstract class to see the output.</p><pre>public class InterfaceVsAbstract {<br><br>    public static void main (String[] args){<br><br>        Dog dog = new Dog();<br>        Bear bear = new Bear();<br><br>        dog.sayHello();<br>        dog.giveBirth();<br>        dog.eat();<br>        dog.clean();<br><br>        bear.sayHello();<br>        bear.giveBirth();<br>        bear.eat();<br>        bear.clean();<br><br>    }<br><br>}</pre><p>Note the following about the output :</p><ul><li>The sayHello() and eat() functions both output something different based on the class it comes from. The function from the interface has different functionality in each class.</li><li>The giveBirth() concrete function outputs the same value and is because it extends the same abstract class. This is an example of how code can be re used implementing abstract classes.</li><li>The clean() function gives different outputs because it is also an abstract function (in the abstract class this time). It is implemented differently in the child classes. This shows that abstract classes can have both concrete and abstract functions.</li></ul><pre>Hello in Dog language = Woof Woof.<br>I am a dog and eat dog food.<br>I am a mammal and I give live birth.<br>I make my owner clean me<br><br>Hello in Bear language = Roarrr.<br>I am a Bear and i eat deer meat.<br>I am a mammal and I give live birth.<br>I bathe myself</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cb84f5fae1b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Camunda process orchestration with external Java tasks.]]></title>
            <link>https://medium.com/@hannovdw1998/camunda-process-orchestration-with-external-java-tasks-ab27b497663e?source=rss-f1bcc03cfa16------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab27b497663e</guid>
            <dc:creator><![CDATA[Hanno Van Der Walt]]></dc:creator>
            <pubDate>Thu, 19 Jan 2023 11:28:57 GMT</pubDate>
            <atom:updated>2023-01-19T11:53:23.821Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4-cJoZZr_XfzGCptbqRA4A.jpeg" /></figure><p>In this article, we will learn how to use the Camunda platform and achieve end-to-end automation using external Java tasks.</p><p>How about we start with what Camunda is? Camunda is software designed for process orchestration and aims to achieve end-to-end automation. It allows us to visualize and create business process flows called BPMN diagrams.</p><p>Camunda can be used in a few different ways, but one of the most popular ways is by using external tasks. The benefit of using external tasks is that the workers that do the work are separated from the Camunda engine and make use of Camunda’s REST API to fetch instances to process. This results in a true decoupled microservice architecture.</p><p>A few of the benefits of using external tasks include but is not limited to independent maintenance, independent scaling, being able to use different programming language per individual task, etc.</p><p>Next, we will get some hands-on experience by making a simple application called ‘let’s fly’.</p><p>Here are my Git repositories for the Camunda Engine and the let’s fly Spring Boot application. Please follow along and refer to it when you are stuck :</p><ul><li><a href="https://github.com/hannovdw/Camunda-Engine">GitHub - hannovdw/Camunda-Engine: Camunda Engine</a></li><li><a href="https://github.com/hannovdw/Lets-Fly">GitHub - hannovdw/Lets-Fly: Lets fly external task Spring Boot application for Camunda</a></li></ul><p>You can start by cloning the Camunda-Engine Git repository and have a look at the lets_go_fly.bpmn file under the resources folder. We can open and edit BPMN files using Camunda Modeler, which you can download <a href="https://camunda.com/download/modeler/">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*-alJePIrA2RKoUyZbehcoA.png" /></figure><p>On a high level overview, the application is for deciding whether you will be going on a flight or not. We will decide if we go for a flight or not by checking if the weather is good enough to go flying and if the aircraft passes the preflight inspection and is safe to fly. We first try to check the weather via an API service and set the isGoodWeather Camunda variable according to the weather. If the weather is good we proceed to do the preflight inspection. If the weather is bad, we cancel our flight and end the process. Then we do the preflight inspection which is also an external task and set the isPassedPFI variable to true or false depending on whether it passed or not. If it passed, we take off, if it failed, we cancel the flight. The weather API can be down from time to time, so if an error is thrown, we can manually approve the weather.</p><h3>Setup</h3><p>In the Lets-Fly Spring Boot project, under the camundaworkers folder, we will find the CheckWeather Java class, which is used for the checkWeather external task. The class uses the service called WeatherService, which generates a random integer and sets the Camunda variables based on the value :</p><pre>@Component<br>@ExternalTaskSubscription(&quot;checkWeather&quot;) // create a subscription for this topic name<br>public class CheckWeather implements ExternalTaskHandler {<br><br>    private final WeatherService weatherService;<br><br>    @Autowired<br>    public CheckWeather( WeatherService weatherService) {<br>        this.weatherService = weatherService;<br>    }<br><br>    @Override<br>    public void execute(ExternalTask externalTask, ExternalTaskService externalTaskService) {<br><br>        Weather weather = weatherService.getWeather();<br><br>        boolean isGoodWeather;<br><br>        isGoodWeather = ((weather.getWindSpeed() &gt; 10) ? false : true);<br><br>        VariableMap variables = Variables.createVariables();<br><br>        variables.put(&quot;isGoodWeather&quot;, isGoodWeather);<br><br>        if(weather.getWindSpeed() &gt; 14){<br>            externalTaskService.handleBpmnError(externalTask , &quot;Simulated_Error&quot;);<br>        }<br><br>        externalTaskService.complete(externalTask,variables);<br><br>    }<br><br>}</pre><p>To enable the external task to poll the Camunda engine for process instances, there are a few things we have to do :</p><p>1.) When clicking on the task block, make sure to choose External under the Implementation dropdown, and choose a topic (in our case checkWeather). Make sure to change the task to a service task by clicking on the wrench icon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*vjlk1UVhacEGcPPo6p474A.png" /></figure><p>2.) Next, we add the topic we chose in the Camunda modeler to the Java external task class in the @ExternalTaskSubscription as shown in the above CheckWeather Java class.</p><p>3.) Update the application.yml file to configure the external workers like in the following code. You have to configure Camunda variable names (that the external task will fetch) isGoodWeather and isPassedPFI, your process definition key (lets_go_fly), and the topic names of the external workers (checkWeather and isPassedPFI).</p><pre>camunda.bpm.client:<br>  base-url: http://localhost:8080/engine-rest # the URL pointing to the Camunda Platform Runtime REST API<br>  lock-duration: 10000 # defines how many milliseconds the External Tasks are locked until they can be fetched again<br>  subscriptions:<br>    checkWeather: # topic name of the External Service Task<br>      variable-names: [isGoodWeather] # our business logic doesn&#39;t require any variables, so don&#39;t fetch them<br>      process-definition-key: lets_go_fly # only filter for External Tasks with this process definition key<br>    preFlightInspection: # topic name of the External Service Task<br>      variable-names: [isGoodWeather, isPassedPFI] # our business logic doesn&#39;t require any variables, so don&#39;t fetch them<br>      process-definition-key: lets_go_fly # only filter for External Tasks with this process definition key<br><br>logging.level.org.camunda.bpm.client: DEBUG # increase the log level of the application<br><br>server.port: 8181</pre><h3>Error Handling</h3><p>Next, we will look at how to handle any errors that occur in the checkWeather external worker. To do this, we need to add an error boundary event to our BPMN diagram :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*rqw5UTWFhtFcVOuZMszqOA.png" /></figure><p>This allows us to catch any BPMN errors thrown from within our external tasks. We used the following code to throw a BPMN error from within our external Java task:</p><pre>externalTaskService.handleBpmnError(externalTask , &quot;Simulated_Error&quot;);</pre><p>The thrown BPMN error then gets caught by the boundary error event and passes it to the user task where we can manually approve the weather.</p><p>Next, we have the preflight inspection external task. It works similar to the CheckWeather worker. Note we also create a subscription using the ExternalTaskSubscription decorator which should align with the application.yml file and the topic name in the BPMN file.</p><pre>@Component<br>@ExternalTaskSubscription(&quot;preFlightInspection&quot;) // create a subscription for this topic name<br>public class PreFlightInspection implements ExternalTaskHandler {<br><br>    @Override<br>    public void execute(ExternalTask externalTask, ExternalTaskService externalTaskService) {<br><br>        boolean isPassedPreFlightInspection;<br>        Random randomNum = new Random();<br>        int randomNumber = randomNum.nextInt(20);<br><br>        isPassedPreFlightInspection = ((randomNumber &gt; 10) ? false : true);<br><br>        VariableMap variables = Variables.createVariables();<br><br>        variables.put(&quot;isPassedPFI&quot;, isPassedPreFlightInspection);<br><br>        externalTaskService.complete(externalTask,variables);<br><br>    }<br><br>}</pre><h3>Starting a process</h3><p>Now that we have a high-level and technical understanding of the application, let’s start a process. To do this we will use Postman to make an HTTP POST request to the Camunda engine like the following :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*8CTKLkHf-vC6g4agAusjVw.png" /></figure><p>URL: <em>localhost:8080/engine-rest/process-definition/key/lets_go_fly/submit-form </em>(make sure to use the port where your Camunda engine is running on)</p><pre>{<br>  &quot;variables&quot;: {<br>      &quot;isGoodWeather&quot; : {&quot;value&quot;:false}<br>  },<br>   &quot;businessKey&quot; : &quot;TestFlight_2&quot;<br>}</pre><p>After sending the request, go to Camunda cockpit on <a href="http://localhost:18080/">http://localhost:18080/</a>. Go into the Let’s Go Fly process definition and you will see your process token on the checkWeather task like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*UWJCCJcV73t9S1tuDmqXZg.png" /></figure><p>Let’s start a few processes using postman and investigate the different paths it can take.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o_-56yjhRf6vvhV0VOdu-A.png" /></figure><p>As you can see, the processes can follow multiple paths based on the variables, let’s look at a few scenarios:</p><ol><li>) the isWeatherGood and isPassedPFI Camunda variables are true and we will take off :</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LCPjs8sJUyuks12twi5BCg.png" /></figure><p>2.) The isGoodWeather Camunda variable is false, and we cancel the flight :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bfqhCOJU-rypclz3wDhqig.png" /></figure><p>3.) Something went wrong while checking the weather and we have to approve manually :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*ZAYmwHBwoBjL-4Ua3cKffA.png" /></figure><p>We can claim the user task and set the isGoodWeather variable manually :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*672s4nS80lS_H66abPR9QA.png" /></figure><p>As we can see Camunda is a very powerful tool and the implementations are endless. If you would like to learn more I recommend you go check out the official <a href="https://camunda.com/">Camunda</a> courses and documentation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab27b497663e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Public vs private Java]]></title>
            <link>https://medium.com/@hannovdw1998/public-vs-private-java-aa1d03c4d52c?source=rss-f1bcc03cfa16------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa1d03c4d52c</guid>
            <dc:creator><![CDATA[Hanno Van Der Walt]]></dc:creator>
            <pubDate>Tue, 13 Dec 2022 09:22:37 GMT</pubDate>
            <atom:updated>2022-12-13T09:45:14.943Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, we will be discussing the differences between the public and private access modifiers that Java provides us with, as well as get some hands-on experience.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ViZYDH07blyJZEVou9GhMA.jpeg" /></figure><p>Access modifiers, also known as specifiers, are used to specify the restrictions of a member, such as a class or function. Java gives us three access modifiers to make use of, namely public, private, and protected. We do not have to use these modifiers and if we choose not to, the member will have default access.</p><h3>Public</h3><p>Starting with public, and to make it a bit easier to understand let’s think of access modifiers as swimming pools with different access. With public swimming pools, anyone from anywhere can make use of it. Same goes for the public access modifier and we can access the variables, classes, and methods from anywhere in the program when we declare it as public.</p><p>Let’s create a class called <em>Pool</em> and define a public function called <em>swim</em>, which prints out some swimming related words:</p><pre>public class Pool {<br><br>  public void swim(){<br>    System.out.println(&quot;Splish Splash in public swimming pool!&quot;);<br>  }<br><br>}</pre><p>Next, create the <em>LetsGoSwim </em>class and implement the main method in which we create a <em>Pool </em>object named <em>publicPool </em>and call the <em>swim </em>function by executing the main method:</p><pre>public class LetsGoSwim {<br><br>  public static void main(String args[]){<br>    <br>    Pool publicPool = new Pool();<br>    publicPool.swim();<br><br>  }<br><br>}</pre><p>The following is the output, and we see the program has no problem accessing the class and its functions:</p><pre>Splish Splash in public swimming pool!</pre><h3>Private</h3><p>Think of the private modifier as a private swimming pool or a pool in your property. Only the people who are on your property and within the walls can swim in it. Same goes for private variables and functions, it can only be accessed or called from within the class where it has been declared and not from anywhere in the program like with public.</p><p>Let’s use the same classes as before, but now let’s make the <em>swim </em>function private :</p><pre>public class Pool{<br><br>  private void swim(){<br>    System.out.println(&quot;Splish Splash in private swimming pool!&quot;)<br>  }<br><br>}</pre><p>When we run the main method, we get the following error. It tells us that we can’t access the swim function in the Pool class because it has private access, and we are trying to call it outside of the class where it has been declared.</p><pre>java: swim() has private access in Pool</pre><p>So, you might be asking how we use these private methods ? Let’s say there is a way to swim in this private pool by asking the owner of the house if you can swim in his pool. He says you can, only if you wear a swimming cap, so your hair doesn&#39;t clog the pumps.</p><p>Let’s make a method called <em>askOwnerToSwim </em>and give it an access modifier of public. Because anyone from anywhere must be able to ask the owner if they can swim in his pool. Let’s also pass the function a Boolean variable <em>isWearingSwimmingCap </em>to indicate whether you’re wearing a swimming cap or not. Inside the function, we check the <em>isWearingSwimmingCap </em>variable, and if it is true, it calls the private <em>swim </em>function.</p><pre>public class Pool {<br>  <br>  private void swim(){<br>    System.out.println(&quot;Splish Splash in private swimming pool with my swimming cap!&quot;);<br>  }<br><br>  public void askOwnerToSwim(Boolean isWearingSwimmingCap){<br><br>    if(isWearingSwimmingCap){<br>      swim();<br>    }<br><br>  }<br><br>}</pre><p>In the main class, we make a Pool object called private pool, and called the askOwnerToSwim method and passed it a Boolean value of true.</p><pre>public class LetsGoSwim {<br><br>  public static void main(String args[]){<br>    <br>    Pool privatePool= new Pool();<br>    privatePool.askOwnerToSwim(true);<br><br>  }<br><br>}</pre><p>When running the above program, we get the following output :</p><pre>Splish Splash in private swimming pool with my swimming cap!</pre><p>Which now works, because we call the private swim function from within the class where it has been declared.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa1d03c4d52c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>