Posts

Use of Private Constructor in OOPS

If we set access specifier of a constructor to private, then that constructor can only be accessed inside the class. A private constructor is mainly used when you want to prevent the class instance from being created outside the class.  This is mainly in the case of singleton class. Singleton classes are employed extensively in concepts like Networking and Database Connectivity. Using private constructor we can ensure that no more than one object can be created at a time.  Example of Private Constructor in a Singleton Class public class SingletonClass {     public static SingletonClass singletonClass;     private SingletonClass()      {     }     public static SingletonClass getInstance()      {         if(singletonClass == null)          {             singletonClass = new SingletonClass();         }         return singletonClass;     } } A class with private constructor cannot be inherited. If we don’t want a class to be inherited, then we make the class constructor private. So, if we

Diamond Problem in Multiple Inheritance in OOPS

Image
The diamond problem occurs when two super classes of a class have a common base class.  Suppose there are four classes A, B, C and D. Class B and C inherit class A. Now class B and C contains one copy of all the functions and data members of class A. Class D is derived from class B and C. Now class D contains two copies of all the functions and data members of class A. One copy comes from class B and another copy comes from class C. Let’s say class A has a function with name display(). So class D have two display() functions as I have explained above. If we call display() function using class D object then ambiguity occurs because compiler gets confused that whether it should call display() that came from class B or from class C. If you will compile above program then it will show error. This kind of problem is called diamond problem as a diamond structure is formed (see the image). That is why major programming languages like C#, Java and Delphi don't have multiple inheritance bec

How to declare Static/Class variables, properties, functions and procedures in Delphi?

In Delphi, we do have static variables, properties, functions and procedures, but instead of the word "static" we refer the word "class". In this tutorial, I have shown the syntax of declaring the static variables, properties, functions and procedures in Delphi. We don't have to use "static" keyword while declaring the static variables and properties, just use "class" keyword. While declaring static functions and procedures, we have to use both "class" and "static" keyword. Declare a static/class variable in Delphi type   TStaticDemoClass = class(TObject)   public     class var StaticVar: integer;   end; Declare a static/class property in Delphi type   TStaticDemoClass = class(TObject)   private     class var FStaticVar: integer;   public     class property StaticVar: integer read FStaticVar write FStaticVar;   end; Now we can use above StaticVar variable/property anywhere in the unit like this: procedure TForm1.Button1C

VCL Hierarchy in Delphi: Types of Controls in Delphi: TWinControls and TGraphicControls

Image
In VCL (Visual Component Library) hierarchy, you will find TObject at the top, then TPersistent, then TComponent and then TControl. TObject >> TPersistent >> TComponent >>TControl VCL Hierarchy in Delphi TObject is the base class from which all classes descend. TPersistent class descends directly from TObject. The special characteristic of TPersistent is that it is an abstract class that defines the methods that allow it to be streamed. TComponent is the base class from which all components descend. Non-visual components are descendants of TComponent. For example: TTimer TControl is the base class from which all the visual components descend. For example: TEdit, TListBox, TComboBox etc. Again, there are two types of controls (TControl): Window Controls (TWinControl) and Graphic Controls (TGraphicControl) Following is the difference between TWinControl and TGraphicControl in Delphi: TWinControls TWinControls can receive input focus and they can be parents to other cont

What is the difference between Singleton Class and Static Class? Which one to use and when?

Almost both singleton class and static class serve the same purpose which creates confusion among developers and architects about which one to use. When to use singleton class and when to use static class. In this article I have tried to differentiate between the two. Following is the list of differences between a singleton class and a static class: 1. Singleton classes are more inclined to the object-oriented concepts as compared to the static classes. With Singleton classes, you can use inheritance and polymorphism to extend a base class, implement an interface and capable of providing different implementations. While a static class cannot inherit their instance members. So, Singleton classes are more flexible than static classes. 2. Singleton classes can be passed as an object to other methods while a static class allows only static methods and you cannot pass static class as parameter. 3. If your requirement is to maintain the state, then singleton class is the better choice than s

Security and Privacy issues with IoT (Internet of Things) - Top barriers to IoT success

IoT is one of the biggest breakthroughs in the history of the tech industry. It will soon be an inherent part of every aspect of our lives. Security and Privacy are the most significant challenge for the IoT. Security and Privacy issues are acting as top barriers to IoT success. So, addressing underlying security and privacy concerns is very crucial.  As more and mored devices are being added to the IoT everyday, privacy and security concerns are becoming vital.  Security issue with IoT devices Security is one of the main concerns of the IoT ("Internet of Things"). With billions of devices connected to the internet, it is needless to say that to protect your connected devices from malware penetrations is a real challenge. Security risks of IoT devices cannot be ignored whether it is from hackers or corporations. Increasing the number of connected devices increases the opportunity to exploit security vulnerabilities. When IoT devices are connected to the cloud or data centers

Real World Examples of IoT (Internet of Things) - How will IoT change our lives?

IoT (Internet of Things) is going to change our lives to a large extent. In the coming years, we will realize the real potential of IoT. Below are some real world examples of IoT. Lets consider  IoT enabled Alarm Clock or say Smart Alarm. Imagine you wake up at 7am every day to go to work. Your alarm clock does the job of waking you just fine. That is, until something goes wrong. Your train is cancelled and you have to drive to work instead. The only problem is that it takes longer to drive, and you would have needed to get up at 6.45am to avoid being late. Oh, and it’s pouring with rain, so you’ll need to drive slower than usual.  A connected or IoT-enabled alarm clock would reset itself based on all these factors, to ensure you got to work on time. It could recognize that your usual train is cancelled, calculate the driving distance and travel time for your alternative route to work, check the weather and factor in slower travelling speed because of heavy rain, and calculate when it