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
3
votes
2 answers

Extending Java Third Party APIs

Its more likely a subjective question. I wanted to create a sub class of a third party API to customize the behavior, but the problem is one of the method in API class is having default access specifier, and I am not allowed to override as my sub…
Satheesh Cheveri
  • 3,621
  • 3
  • 27
  • 46
2
votes
2 answers

android activitygroup and listactivity

I need to have a List in an Activity that is in a TabHost. The list gets opened when a button is clicked. I however want the new activity to open up and keep the tabs on top, so I created a class, TabActivityGroup, that extends the ActivityGroup and…
2
votes
2 answers

How were "classes" extended prior to class syntax and Object.create?

I have not been able to find an answer to this. Objects in JavaScript have an inheritance chain; the chain of any function is Function => Object, the chain of an instance of TypeError is TypeError => Error => Object, and the chain of TypeError is,…
2
votes
1 answer

Extending WooCommerce COD payment gateway in a plugin

I would like to understand the sequence various classes are loaded in Wordpress. There are many plugins available in Wordpress, then who will be loaded earlier than another. Consider I would like to develop a plugin that will use some existing class…
2
votes
1 answer

How to extend a functionN class in Scala

I am new to Scala. I have a Class A that extends a Class C. I also have a Class B that also extends a Class C I want function objects of type A->B to extend C as well (and also other derived types, such as A->(A->B)). But I read in "Programming in…
2
votes
1 answer

Unable to Extend Class from Dictionary of Classes

ISSUE: I am attempting to return a class declaration from a higher order class method that extends a class from a class map {"SOME_CLASS" : SomeClass} thats key is a parameter of the higher order class method. However Typescript is throwing this…
2
votes
1 answer

Extend spinner with same design

I would like to extend the spinner class, but preserve the same look. If I just create a custom spinner class like (nothing special happening): public class MySpinner extends Spinner { public MySpinner(Context context) { super(context);…
2
votes
3 answers

Laravel - Extending Model

I've created a BaseModel class, which extends from Model. It seemed like everything was working fine, but now I've run into a problem when saving. I'm overriding the save() method in this BaseModel. I'd just like to add some attributes to the model…
kenshin9
  • 2,215
  • 4
  • 23
  • 38
2
votes
1 answer

rails named_scope as an extension to AR::Base

class SomeModel < ActiveRecord::Base named_scope :recent, lambda { { :conditions => ['created_at > ?', 1.week.ago] } } end I want to extend the AR::Base class to have this named_scope for all models, how I can do this ?
astropanic
  • 10,800
  • 19
  • 72
  • 132
2
votes
3 answers

How do I extend the String class?

Extending core classes in javascript is dead easy. I get the impression it's not quite so easy in C#. I was wanting to add some things to the String class so that I could do stuff like: string s = "the cat's mat sat"; string sql =…
bugmagnet
  • 7,631
  • 8
  • 69
  • 131
2
votes
1 answer

Extending the Auth User and Group models in Django

I initially extended only the Group model, and although I got the extra fields working correctly, I end up with inconsistent results when I switch back to the auth-user model: group1 = MyGroup(..) user = group1.user_set.all()[0] group2 =…
steve-gregory
  • 7,396
  • 8
  • 39
  • 47
2
votes
2 answers

PHP class extending another class outside of folder

I have a general class which i like to have it extended by other classes. I have my directory set up with folders and class files inside of those folders for example Classes/users/users.class.php classes/general/general.class.php I have the users…
Yeak
  • 2,470
  • 9
  • 45
  • 71
1
vote
1 answer

Error on MSVC++ with extending iostream

I'm writing an output manager class for my application and although my class works on g++ under linux, it won't compile under MSVC++ 2010. Here is a SSCCE version of my program : #include #include #include #include…
1
vote
1 answer

Extending nokogiri in a rails app

I extended the Nokogiri::HTML:Document class as follows to add a function called on_same_line? module Nokogiri module HTML class Document def on_same_line?(node1,node2,font_sizes) return false if node1.nil? or node2.nil? or…
ppaul74
  • 751
  • 1
  • 13
  • 21
1
vote
1 answer

extending Node.addEventListener method with the same name

I'm trying to extend the Node.addEventListener method so I can do some events management like: Node.prototype.on = function (type, listener, useCapture) { 'use strict'; var i, evt; this.events = this.events || []; for (i = 0; i <…
zanona
  • 12,345
  • 25
  • 86
  • 141