Saturday, December 12, 2020

Learn Abstract Class and Interface - Day 11

 In this article .we are learn Abstract Class and Interface.

Abstract Class:

  • Abstract class is declared by using keyword abstract.
  • Abstract classes are mainly for inheritance where other classes may derive from them.
  • An abstract class can be derive by using ‘extends’ keyword. 
  •  We cannot create an instance of an abstract class.
  • Abstract class is a class that includes both abstract and regular methods.
  • Methods within abstract class which are marked as abstract do not contain an implementation and must be implemented in derived classes. 
  • So the  abstract class is used for inheritance where other classes are derived from abstract class.
  • Syntax:-
abstract class ClassName{

//variables declaration;
//abstract or non-abstract methods;

}





Interface:
  • It is like a blueprint of class, only method implementation is not possible in interface.
  • It contains properties, methods & events.
  • Users have to give method definitions in implemented class of interfaces.
  • We can implement an interface by using the implements keyword in class.
  • An interface is a contract which defines a function with respect to parameters or arguments and data types.
  • Interface supports multiple inheritance.
  • Interface can't contains the implementation of abstract class.
  • Syntax:
interface InterfaceName{    

     // properties, methods & events

}   






Thank you....

Friday, December 11, 2020

Learn Inheritance and Constructor in Typescript- Day 10

 In this article, We are learn Inheritance and Constructor.


Inheritance:

  •  TypeScript supports the concept of Inheritance.
  • Inheritance is the ability of a program to create new classes from an existing class. 
  • The class that is extended to create newer classes is called the parent class/super class.
  •  The newly created classes are called the child/sub classes.
  • A class inherits from another class using the ‘extends’ keyword. 
  • Child classes inherit all properties and methods except private members and constructors from the parent class.
  • There are 5 types of inheritance:
         1.Single Inheritance
         2.Multilevel Inheritance
         3.Multiple Inheritance
         4.Hybrid Inheritance
         5.Hierarchical Inheritance

  • Syntax:

class child_class_name extends parent_class_name


Why use inheritance?

  • We can use it for Method Overriding (so runtime polymorphism can be achieved).
  • We can use it for Code Reusability.

 



Note: TypeScript supports only single and multilevel inheritance. It doesn't support multiple, hierarchical, and hybrid inheritance.


1.Single Inheritance

  • Single inheritance can inherit properties and behavior from at most one parent class. 
  • It allow a derived/subclass to inherit the properties and behavior of a base class that enable the code reusability as well as we can add new features to the existing code.

2.Multilevel Inheritance

  • When a derived class is derived from another derived class, then this type of inheritance is known as multilevel inheritance.
  •  Thus, a multilevel inheritance has more than one parent class.

Example:






Access Modifiers:

  • The access modifiers are used for controlling the visibility or availability of its data members.
  • There are three types of access modifiers in TypeScript: public, private and protected.

1.Public - 

  • By default members (properties and methods) of TypeScript class are public - so you don’t need to prefix members with the public keyword. 
  • Public members are accessible everywhere without restrictions.

 2.Private -

  • A private member cannot be accessed outside of its containing class.
  •  Private members can be accessed only within the class.

3.Protected -

  • A protected member cannot be accessed outside of its containing class. P
  • Protected members can be accessed only within the class and by the instance of its sub/child class.

Example of Access Modifier:





Constructor:

  • In TypeScript, the constructor method is always defined with the name "constructor".
  • Constructors are identified with the keyword "constructor". 
  • A Constructor  is a  special type of method of a class and it will be automatically invoked when an instance of the class is created. 
  • A class may contain at least one constructor declaration. 
  • If a class has no constructor, a constructor is provided automatically. 
  • A Class can have any number of constructors. 
  • When you are using the attribute public or private with constructor parameters, a field is automatically created, which is assigned the value.
  • Syntax :

           constructor () {

          // statement

            }                

   Example:                       








Thank you.....










Tuesday, December 8, 2020

Learn Basic Concept in TypeScript Day -9

 In this article ..we are learn basic concept in TypeScript.



Variable Declaration:




Variable: Variable is a named place in memory where some data/value can be stored. According to the word variable, it can be said that the value of a variable can be changed/vary. 


While declaring a variable  some rules have to be followed:

1. Variable  name can contains alphabets both Upper-case as well as Lower-case and digits also.
2.Variable name cant start with digit.
3.We can use _ and $ special character only, apart from these other special characters are not allowed.


Variable declaration: 

A variable must be declared before it is used.use the bar keyword to declare a variable.
We  can declare a  variable in  multiple ways like below:

var Identifier:Data-type = value;
var Identifier: Data-type;
var Identifier = value;
var Identifier;


Examples:

1.var name:number = 10; Here name is a variable which can store only Integer type data.

2.var name:number; Here name is a variable which can store only Integer type data. But by
default its value set to undefined.

3.var name = 10; Here while declaring variable we are not specifying data-type. Therefore
compiler decide its data type by seeing its value i.e. number here.

4.var name; Here while declaring variable we are not specifying data-type as well as we are not 
assigning any value also. then compiler takes its data type as any.its value is set to undefined by default.


Creating object:

  • An object is an instance of class which contains set of key value pairs.
  •  It’s value may be scalar values or functions or even array of other objects.
  
Syntax of creating a object:

var object_name = new class_name();



Creating class:

  • Class 
    term of OOPs is a blueprint for creating objects.
  • In class group of objects which have common properties. 
  • Class contain fields, methods,  constructors, Blocks, Nested class and interface.
  • Use the class keyword to declare a class in TypeScript.

Syntax to declare a class:

class class_Name{    
    field;    
    method;    
}


Import:

  • Importing is just about as easy as exporting from a module. 
  • A statement to use primitive values, objects, functions, or classes that are exported from another module. Typically, an import is static, but it can be dynamic too
  • Importing an exported declaration is done through using one of the import forms below:
  • Import a single export from a module
import { ZipCodeValidator } from "./ZipCodeValidator";
let myValidator = new ZipCodeValidator();


Example:





Export:

  • A statement to export primitive values, objects, functions, or classes from the module for the purpose of being used by other modules.
  • Exporting a declaration Any declaration (such as a variable, function, class, type alias, or interface) can be exported by adding the export keyword.

    StringValidator.ts
    export interface StringValidator {
      isAcceptable(s: string): boolean;
    }

Example:






TypeScript Configuration:

  • The tsconfig.json file indicates the root directory of TypeScript.
  • The tsconfig.json file specifies the root files as well as the compiler options for compiling a program.
  • As we run tsc command for each .ts file for converting it into .js file. The tsconfig.json file converts the all .ts file into .js and make our work easy.
  • For tsconfig.json file run following command on terminal :
                             > tsc --init
  • The above command automatically creates a tsconfig.json file.



  • We can use a "outDir" for creating a new folder which having the .js files of our module, as i created in above image.







Thank you...

Saturday, December 5, 2020

Learn TypeScript Day-8

 In this article, we are learn TypeScript.


What is TypeScript:



  • TypeScript is a modern age Javascript development language. 
  • It is a statically compiled language to write clear and simple Javascript code. 
  •  Typescript provides optional static typing, classes, and interface.
  • Typescript is a modern age Javascript development language. 
  • It can be run on Node js or any browser which supports ECMAScript 3 or newer versions.
  • TypeScript is a programming language developed and maintained by Microsoft.
  • As TypeScript is a superset of JavaScript, existing JavaScript programs are also valid TypeScript programs. 
  • TypeScriptis an open-source pure object-oriented programing language. 
  • It is not directly run on the browser. It needs a compiler to compile and generate in JavaScript file. 
  • Typescript source file is in ".ts" extension. We can use any valid ".js" file by renaming it to ".ts" file.
  •  TypeScript is the ES6 version of JavaScript with some additional features.



Advantage of TypeScript over JavaScript:

  • TypeScript always highlights errors at compilation time during the time of development, whereas JavaScript points out errors at the runtime.
  • TypeScript supports strongly typed or static typing, whereas this is not in JavaScript.
  • TypeScript runs on any browser or JavaScript engine.


Disadvantage of TypeScript over JavaScript:

  • TypeScript takes a long time to compile the code.
  • TypeScript does not support abstract classes.
  • If we run the TypeScript application in the browser, a compilation step is required to transform TypeScript into JavaScript.


JavaScript vs Typescript:



  • JavaScript is a scripting language which helps you create interactive web pages whereas Typescript is a superset of JavaScript.
  • Typescript code needs to be compiled while JavaScript code doesn’t need to compile.
  • Typescript supports a feature of prototyping while JavaScript doesn't support this feature.
  • Typescript Uses concepts like types and interfaces to describe data being used whereas JavaScript has no such concept.
  • Typescript is a powerful type system, including generics & JS features for large size project whereas JavaScript is an ideal option for small size project.


Why Typescript?

  • TypeScript supports JS libraries & API Documentation.
  • It is a superset of Javascript.
  • It is optionally typed scripting language.
  • TypeScript Code can be converted into plain JavaScript Code.
  • Better code structuring and object-oriented programming techniques.
  • Allows better development time tool support.


What is better?

In the end, we can say that if an experienced developer is working on relatively small coding projects, then JavaScript is ideal. However, if you have knowledge and expertise development team, then Typescript is a most preferred option.



Thank you.....














Function in SQL -part 8

  In this blog we are going to understand  Sql function.   FUNCTION: A function is a database object in SQL Server. It accepts only input pa...