0% found this document useful (0 votes)
9 views3 pages

Angular Basics 3

Uploaded by

vishalwdv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Angular Basics 3

Uploaded by

vishalwdv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

**Typescript as an object oriented language

-------------------------------------------
Object oriented approach is a programming paradigm in which everything is modelled
as an object

we implement OOPs by writing classes & creating objects

Writing a class in Typescript


-TS filename & classname name can be anything

- Data members are created without let keyword.

-constructor is defined using constructor keyword , not classname

-we can have only one ctor in typescript class[default/parameterized]

-using this is mandatory inside a TS class

-when we define a function inside a class,we dont use the keyword function
function globalfunc():void{....}

class MyClass{
localfunc():void{....}

}
___________________________________________________________

Lab1)Player.ts
write a class Player having data members
playerId,playerName,country,numMatches

write ctor & DisplayInfo member function

Inheritance
-----------
is a property by the virtue of which an object is derived from other object
or an object acquires features of the other object

class A{....}
class B extends A{....}

Here A is a super/parent/base class


Here B is a subclass/child/derived class

eg:-
class Employee{empId,empName,jdate}

class Manager extends Employee{basicSal,incentives}


class WageEmployee extends Employee{hours,rate}

we can create an array of super type which holds subclass objects[generic


reference]

let earr:Employee[]=[];
earr.push(new Manager(....));
earr.push(new WageEmployee(....));
**super keyword is available to evry subclass to access any member of super class

Lab3) Inheritance topic


Batsman.ts
------------
Write a class Batsman extends Player-->numRuns
ctor,DisplayInfo

Bowler.ts
------------
Write a class Bowler extends Player-->numWickets
ctor,DisplayInfo

caller.ts
---------
create an array of Player type---team holding 2 Batsman object & 2 Bowler objects
& display all players using for-of loop

eg:
let team:Player[]=[p1,p2];
here p1 is a Batsman object
& p2 is a Bowler object
_________________________________________________________

Polymorphism:

class A{...}
How to use this class A?

1)creating object
let ob:A=new A();

2)by extending it
class B extends A{....}

but when we want the class only to be extending

abstract class A{...}


//Abstract class is a class which cannot be instantiated but needs to be extended

interface in Typescript
-----------------------
Interface is a pure abstract class

is a contract[set of specifications]

is a set of method declrations which needs to be implemented by some class

interface tells a class what to do ,not how to do

used to implement Polymorphism

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 Performer{void Perform();}

Participants.ts
---------------
write 3 classes which implements interface
Juggler[beanBags]
Singer[song]
Magician[magicWords]

SeedIdol.ts
------------
create an array of Performer & 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"));
________________________________________________________

CaseStudy on Inheritance & Encapsulation using property fn


Lab3)
student.ts
-----------
Write a class Student[rollNo,name,marks-array of 5 subjects]
2 subclasses
PrimaryStudent[grade]
SecondaryStudent[percentage]

In all above 3 classes write constructor,PrintMarkSheet

callerStudent.ts
----------------
create an array of Students & invoke PrintMarkSheet method

You might also like