Calling abstract classes in TypeScript

Abstraction is an Object Oriented programming concept whereby a class can specify how an inherited class should implement the class itself, including any abstract methods specified.The concept of abstraction is we are hiding the complexity of the implementation from inherited classes and we allow them to implement the functionality themselves . 

Abstraction can be achieved by using the abstract keyword - which can be applied to both classes and methods specified in classes.

Let's take an example of abstract class :

abstract class Warrior {
  readonly name: string;
  public weapon: string;
  constructor(name: string) {
    this.name = name;
  }

  abstract arm(weapon: string): void;
}


If we now attempt to instantiate this class we'll get an error:

const peter = new Warrior('Peter, the Nomad'); // Cannot create an instance of the abstract class 'Warrior'.

Now we need to implement the abstract class then we need to create a subclass and extend it using the extends keyword.

class SuperWarrior extends Warrior {
  constructor(name: string) {
    super(name);
  }
  arm(weapon: string): void {
    console.log(`${this.name} is a super warrior fighting with ${weapon}`);
  }
}


Now we have a subclass we can create our warriors.

const warrior = new SuperWarrior('John, the Nomad');
warrior.arm('lance'); // John, the Nomad is a super warrior fighting with lance



we can also utilise Interfaces and implement them for classes

interface IWarrior {
  name: string;
  weapon: string;
  arm(weapon: string): void;
}
abstract class Warrior implements IWarrior {
  readonly name: string;
  public weapon: string;
  constructor(name: string) {
    this.name = name;
  }

  abstract arm(weapon: string): void;
}

class SuperWarrior extends Warrior {
  constructor(name: string) {
    super(name);
  }
  arm(weapon): void {
    console.log(`${this.name} is a super warrior fighting with ${weapon}`);
  }
}

const warrior: IWarrior = new SuperWarrior('John, the Nomad');
warrior.arm('lance');

Install Machine Learning Tool in Python

In this article i will show you how to install tensorflow in python3. It's quite easy in ubuntu to set the tensorflow which is an open-source machine learning software.

Run the following commands/script to get tensorflow (CPU only) installed on your Ubuntu 16.04 server.

# Install necessary python packages.
sudo apt-get install python3-pip python3-dev -y

# Upgrade pip using this
pip3 install --upgrade pip

# Install tensorflow (cpu only)
pip3 install tensorflow

If you want to use an NVIDIA GPU for tensorflow then run this instead:

# Install necessary python packages.
sudo apt-get install python3-pip python3-dev -y

# Upgrade pip
pip3 install --upgrade pip

# Install tensorflow with GPU support
pip3 install tensorflow-gpu

That seemed a little too easy, so let's just write a small test script that uses the tensorflow library that we have installed it correctly:

#!/usr/bin/python3
import tensorflow as tf
hello = tf.constant("Hello, Tensflow!")
sess = tf.Session()
print(sess.run(hello))

If you execute this output should be :

b'Hello, Tensflow!'

Now you have successfully installed tensorflow in your system. If you want to read more about the tensorflow then follow the link.


Symfony console command basics

Let's take a look on symfony command.It very easy in symfony to check the existing command and list of all commands. Execute the following to check all the existing feature commands in console.

symfony console commands basics


run this command in your root directory,

php bin/console


You will see a list of existing commands. Each supported command has a short details. Each of the standard commands come with help, so I will not be describing each of them here, but it is worth to mention a few commonly used ones:

php bin/console: cache:clear

Symfonys in production store more data in caching. Therefore, if you need to change values within a template (Twig) or within configuration files while in production mode, you will need to clear the cache. Cache is also one of the reasons why it’s worth to work in the development mode.

php bin/console container:debug

Displays all configured public services in symfony.

php bin/console router:debug

It will displays all routing configuration along with method, scheme, host, and path.

php bin/console security:check

Checks your composer and packages version against known security vulnerabilities. You should run this command regularly.

Download the eBook of react js for beginners

ReactJS basically is an open-source JavaScript library which is used for building user interfaces specifically for single page applications...

Popular