inheritance
Pay attention to the fact that “is-a” relationship exists between base and the derived class. In example below, ITCompany (derived class) “is-a” Company (base class). The class which is inherited is called as “base” class and the class that inherits is called as derived class. Pay attention to some of the following in relation with inheritance:
ITCompany.prototype = new Company();
// Class Company modeling any company
// This represents what is called as base class; Later, we shall make derived class which inherits
// the properties and methods of this class
function Company(name) {
this.name = name;
this.type = 0;
this.employee = 0;
this.getName = function() {
return this.name;
}
this.getType = function() {
return this.type;
}
this.setEmployee = function(count) {
this.employee = count;
}
this.getEmployee = function() {
return this.employee;
}
}
function ITCompany(name) {
this.name = name;
this.getType = function() {
return 2;
}
}
// Lets make an instance of class Company
//
var rel = new Company( "Reliance Pvt Ltd" );
console.log( rel.getName() ); // Prints Reliance Pvt Ltd
console.log( rel.getType() ); // Prints 0
console.log( rel.getEmployee() ); // Prints 0
rel.setEmployee( 150000 );
console.log( rel.getEmployee() ); // Prints 150000
// Lets create an instance of ITCompany
//
var hcl = new ITCompany( "HCL Technologies" );
console.log( hcl.getName() ); // Prints "undefined is not a function"
// Lets inherit the ITCompany from Company; This is also natural as
// an ITCompany "is a" Company.
// Pay attention that "prototype" is used with ITCompany to inherit the properties and
// methods of base class
ITCompany.prototype = new Company();
var hcl = new ITCompany( "HCL Technologies" );
console.log( hcl.getName() ); // Prints "HCL Technologies"
hcl.setEmployee( 125000 );
console.log( hcl.getEmployee() ); // Prints 125000
console.log( hcl.type );
console.log( hcl.getType() );
Retrieval-Augmented Generation (RAG) is an innovative generative AI method that combines retrieval-based search with large…
The combination of Retrieval-Augmented Generation (RAG) and powerful language models enables the development of sophisticated…
Have you ever wondered how to use OpenAI APIs to create custom chatbots? With advancements…
When building a Retrieval-Augmented Generation (RAG) application powered by Large Language Models (LLMs), which combine…
Last updated: 25th Jan, 2025 Have you ever wondered how to seamlessly integrate the vast…
Artificial Intelligence (AI) agents have started becoming an integral part of our lives. Imagine asking…