简体   繁体   English

是否可以扩展类而不扩展此类的方法?

[英]Is it possible to extend a class without extending the methods of this class?

The title says it all. 标题说明了一切。 I have a class with a lot of variables and a lot of methods in it. 我有一个包含很多变量和很多方法的类。

class bootstrap_class { 
public
//-----Counters--------- 
$iColumn_count,
$iLink_count,
$iDia_count,
$iTab_count,
$iPadding,
$iColumns_per_page,

//-----Strings---------
$sCentered, 
$sClass,
etc;

public function a () {
    //do something
}

public function b () {
    //do something
}
}

I am trying to extend this class to create a class without all the methods. 我正在尝试扩展此类,以创建没有所有方法的类。 I then want to store this new class object into an array variable in the parent class. 然后,我想将此新类对象存储到父类中的数组变量中。

Is it possible to extend a class without extending the functions of that class? 是否可以扩展类而不扩展该类的功能?

It is not possible the way you want it. 不可能以您想要的方式。 But The following is the only way to do it. 但是以下是唯一的方法。

All you have to do is change the methods' visibility to private from public in parent class. 您要做的就是将方法的可见性从父类的public更改为private See below for details. 有关详情,请参见下文。

what are public private and protected in Object Oriented Programming 面向对象编程中哪些是公共私有的,哪些是受保护的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM