Questions tagged [extending-classes]

Method extending, in object oriented programming, is a language feature that allows a subclass or child class to inherit all the methods and properties of the extended class.

You can extend a class to provide a more specialized behavior.

A class that extends another class inherits all the methods and properties of the extended class. In addition, the extending class can override the existing methods. Overriding a virtual method allows you to provide a different implementation for an existing method. This means that the behaviour of a particular method is different based on the object you're calling it on. This is referred to as polymorphism.

A class extends another class using the extends keyword in the class definition. A class can only extend one other class.

Example in PHP

class Hello {
    public function message() {
        return "Hello";
    }
}

class HelloWorld extends Hello {
    public function message() {
        return parent::message() . " World";
    }
}

$class = new HellowWord();
echo $class->message(); //"Hello World"

In this example we the class Hello, and the function message.

Related tags:

100 questions
1
vote
1 answer

How to extend Illuminate\Database\Query\Builder

I'm planning to have a function that will store the sql statement on the Cache using the given second parameter on remember() as the key and whenever the sql statement changes it will run against the database again and overwrite the stored sql, also…
lukaserat
  • 4,768
  • 1
  • 25
  • 36
1
vote
0 answers

Android :The Application has stopped unexpectedly

I am creating a live wallpaper app in which there is a random slideshow of pictures along with little thumbnails at the bottom that can be clicked on. I had to extend multiple classes & I think that is where i am stuck.Please help. Live Wallpaper…
user2125722
  • 1,289
  • 3
  • 18
  • 29
1
vote
2 answers

WooCommerce Extending WC_Shipping_Method error: Class 'WC_Shipping_Method' not found

The title explains it pretty well. I'm trying to add a new shipping method (cost-based shipping) by extending the class. Here is the plugin body (The rest is in comments and contains the plugin info): class WC_Cost_Based extends WC_Shipping_Method…
Alfred Xing
  • 4,406
  • 2
  • 23
  • 34
1
vote
1 answer

Extending Core Class Codeigniter - 404 Error

I am trying to learn Codeigniter. I am trying to use application/core/MY_Controller in my CI application. MY_Controller.php as: class MY_Controller extends CI_Controller { protected $data = array(); function __construct() { …
ytsejam
  • 3,291
  • 7
  • 39
  • 69
1
vote
1 answer

Class extend in php assistance

I have a autoload function that looks like so: function __autoload_HTTP_Client($class_name) { $HC = $class_name . '.class.php'; return require_once($HC); } when i call a class i use the $users = new users(); What i want to do is place my…
Yeak
  • 2,470
  • 9
  • 45
  • 71
1
vote
2 answers

Extending Loader

I´m trying to extend the Loader class. I want to store a variable on it. Example: package { import flash.display.Loader; public class MyLoader extends Loader { private var _typeOfGallery:String public function MyLoader() { …
Marcelo Noronha
  • 807
  • 2
  • 12
  • 26
0
votes
1 answer

Extending event emitter with class

I have problem to correctly create EventEmitter with Listener instances inside, and use it with extending. I want to create Event Emitter that can be extended by additional events by child class if there is any extending. Let's look at my code, and…
0
votes
0 answers

Why is extending Date() only working on some browsers?

I'm extending the Date class in a Typescript project. (Edit: I've simplified this code slightly into a more barebones version) class ExtendedDate extends Date { get fullYear() { return this.getFullYear(); } } export class DateTest…
0
votes
0 answers

How to extend classes with same property in nestjs typescript

I'm extending AuthService class to UserAuthService class extracting common functionality so I can extend it to other services like AdminAuthService Here's how the code looks like: import { Inject, Injectable, UnauthorizedException } from…
Rohit Khatri
  • 1,980
  • 3
  • 25
  • 45
0
votes
0 answers

How can I successfully work with multiple Default List Models in Java?

firstly, thank you for any help in advance. I'm working on a personal project while in school - I would like to make a Table Top System Manager that my wife and I can use to run our homebrewed systems. Current Road-Block: Working with multiple…
AJBarkus
  • 1
  • 1
0
votes
1 answer

Composition or inheritance when extending std::vector?

I want to create a html query object that has all the properties of a vector (can be iterated through, has all the access functions) BUT it should parse the input first before storing it, so a string like "/my/websites/path" should be split into 3…
glades
  • 3,778
  • 1
  • 12
  • 34
0
votes
0 answers

Trying to extend ActionMailer::MessageDelivery

I would like to extend the MessageDelivery class in the ActionMailer module and am not successful in my attempts. From what I have read, it should be as simple as: module ActionMailer class MessageDelivery def deliver_at_next_time_interval…
0
votes
0 answers

django 'User' object has no attribute 'profile' while using post_save

This error is showing while login to admin panel " 'User' object has no attribute 'profile' " from django.db import models from django.contrib.auth.models import User from django.db.models.signals import post_save from django.dispatch import…
0
votes
1 answer

Understand Typescript syntax around Type assertions/casting

I'm a newbie to TypeScript. I've been looking to find elegant patterns to define Mongoose schemas using TypeScript. I've been studying an article by Nicholas Mordecai at: https://know-thy-code.com/mongoose-schemas-models-typescript/ It's a very…
0
votes
1 answer

Create tasks[] an array of task

My current problem is that I am assigned to created a program that should within the private fields assign tasks[] an array of task. Then within the constructor, that creates the task[] array, giving it the capacity of INITIAL_CAPAITY, and setting…