class

Check if object is a 'direct instance' of a class

邮差的信 提交于 2020-01-02 02:12:46
问题 I have two classes: class Bar extends Foo { // Foo isn't relevant constructor(value) { if (!(value instanceof Foo)) throw "InvalidArgumentException: (...)"; super(); this.value = value; } } class Baz extends Bar { constructor(value) { super(value); } } The Bar constructor checks if value is an instance of Foo, it throws an error if it isn't. At least, that's what I wanted it to do. If you pass a Bar or a Baz as value, the if-statement returns true as well. The goal is to only let Foo s

How can I call member variables of a class within a static method?

笑着哭i 提交于 2020-01-02 01:55:47
问题 I am using some method to autoload helper files with functions. The only problem I am having now, is how to call the variables in that class. Because I am not instantiating it as an object, $this won't work. But what will? class some_helperclass { var $some_variable = '007'; public static function some_func() { //return 'all ok'; if (self::some_variable !== FALSE) { return self::ip_adres; } } I can call the function from anywhere now with the help of spl_autoload_register() . some_helperclass

Anonymous class construction

…衆ロ難τιáo~ 提交于 2020-01-02 01:47:10
问题 I need an idea to create anonymous class on PHP. I don't know how I can works. See my limitations : On PHP you can't make anonymous class, like anonymous function (like class {} ); On PHP you don't have class scope (except in namespaces, but it have the same problem below); On PHP you can't use variables to specify the class name (like class $name {} ); I don't have access to install the runkit PECL. What I need, and why : Well, I need create a function called ie create_class() that receives

Angular : Class and Interface [closed]

≡放荡痞女 提交于 2020-01-02 01:22:08
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 11 months ago . I’m here today because I’ve a question about, like the title said, about classes and interfaces in Angular . From my Point of View, I understand this: Interfaces are used in Typescript to perform type-checking , they are here until the transpilation and disappear in the

C++ To filter a class vector using algorithm

不想你离开。 提交于 2020-01-02 00:54:13
问题 How can I filter a class vector, studentList by its country from using algorithm? Meaning I only display the detail of students from country "America". bool checkCountry (string x, string y) { return (x == y); } vector<Student> studentList; studentList.push_back(Student("Tom", 'M', "91213242", "America")); studentList.push_back(Student("Jessilyn", 'F', "98422333", "Europe")); 回答1: using std::copy_if; using std::ostream_iterator; using std::cout; enum Region { AMERICA, EUROPE, REST_OF_WORLD };

Class attribute declaration: private vs public

*爱你&永不变心* 提交于 2020-01-02 00:52:13
问题 What are the advantages of defining a private attribute instead of a public attribute? Why should I have the extra work of creating methods to access and modify privates attributes if I can just make them public? 回答1: If you use getters/setters you can perform logic upon changes or access. You could validate input, instead of assuming it is always correct. You could track how many times the value is fetched. Most of all, it's good design. It gives you, the developer of the class, more control

what is a singleton class? Can it help me running single instance of a class for two related services?

自作多情 提交于 2020-01-01 19:55:14
问题 This might sound complex but i will ask anyway: I am running a service A which uses class X . I want to start another service B which uses classes A besides new classes. Service A is already running. I do a hot deployment of Service B . Here is the real question - Will Service B use the same instance of class X or a separate instance. How can singleton class help me here? 回答1: Each Service will run in it's own operating System (OS) Process space, and each process space has it's own class

Deleting a class object in java

自作多情 提交于 2020-01-01 18:02:05
问题 I have a class named Point as below: public class Point { public int x; public int y; public Point(int X, int Y){ x = X; y = Y; } public double Distance(Point p){ return sqrt(((this.x - p.x) * (this.x - p.x)) + ((this.y - p.y) * (this.y - p.y))); } protected void finalize() { System.out.println( "One point has been destroyed."); } } I have an object from this class named p as below: Point p = new Point(50,50); I want to delete this object, I searched how to do it, the only solution I found

Scan all classes for a given custom attribute

ぃ、小莉子 提交于 2020-01-01 17:28:06
问题 I'm looking for a way of scanning all loaded classes for classes which contain a custom attribute, if possible, without using RegisterClass(). 回答1: at first you have to create TRttiContext , then get all loaded classes using getTypes . after that you can filter types by TypeKind = tkClass ; next step is to enumerate attributes and check if it has your attribute; attribute and test-class delcaration: unit Unit3; interface type TMyAttribute = class(TCustomAttribute) end; [TMyAttribute] TTest =

A way to inherit from multiple classes

给你一囗甜甜゛ 提交于 2020-01-01 17:03:57
问题 I have two classes I want to use in my new class. The first one implements a swipe to delete and the second enables a long press gesture: class DeleteItem: UITableViewCell { } class OpenDetail: UITableViewCell { } Since Swift doesn't allow a class to inherit from multiple classes the following example obviously won't work: class ItemViewCell: DeleteItem, OpenDetail { } So in order to create ItemViewCell and having both options, I'll have to have one of the classes to inherit from each other: