Angular Basics 4
Angular Basics 4
class A{...}
How to use this class A?
1)creating object
let ob:A=new A();
2)by extending it
class B extends A{....}
abstract class A{
//data member
//non-abstract functions
//abstract methods (methods which has only declaration and no implementation)
abstract Fun1():void;
}
abstract class C {}
class B extends A
{
Fun1():void
{
}
}
//Abstract class is a class which cannot be instantiated but needs to be extended
interface IA
{
fun1():void;
fun2():void;
}
class MyClass implements IA
{
fun1() : void {}
fun2(): void{}
}
interface in Typescript
-----------------------
Interface is a pure abstract class
is a contract[set of specifications]
used to implement Polymorphism (Many Forms) : Compile Time & RunTime(samename &
same signature in base type and derived type)
Lab1)
ITune.ts
---------
create an interface ITune having a method Play()
Instruments.ts
--------------
write 3 classes Guitar,Piano & Violin implementing the interface ITune
CallerInstrument.ts
-------------------
create an array instruments:ITune[] holding Guitar,Piano & Violin objects & invoke
Play method
____________________________________________________________
Lab2)
Performer.ts
-------------
interface IPerformer{ Perform():void;}
Participants.ts
---------------
write 3 classes which implements interface
Juggler[beanBags]
Singer[song]
Magician[magicWords]
SeedIdol.ts
------------
create an array of IPerformer & invoke Perform method onit
let parr:Performer[]=[];
parr.push(new Juggler(5));
parr.push(new Singer("some song"));
parr.push(new Magician("some magic words"));
________________________________________________________
callerStudent.ts
----------------
create an array of Students & invoke PrintMarkSheet method
Creating Properties:
private _eid:number;
get Eid:number { return _eid;} //getter method ------only get --
readonly property
set Eid(n1:number) { _eid = n1;} //setter method --------only set ---
writeonly
Another way to hide the data members is to declare them inside constructor
Class A
{
constructor(private a:number)
{}
Display():void
{Console.log(this.a);}
class A
{
private a:number;
public b:number;
protected c:number;
}
class B extends A
{
Display():void
{
//access for b and c is possible
}
}