Tags "class" Result

What's an example use case for a Python classmethod?

I've read What are Class methods in Python for? but the examples in that post are complex. I am looking for a clear, simple, bare-bones example of a particular use case for classmethods in Python. Can you name a small, specific example use case where a Python classmethod would be the right tool for the job? Solution Helper methods for initiali

it1352 2 2019-05-13

C Access private member of nested class

The title might be a bit misleading. I have the following problem: I have a tree consisting of leaves and internal nodes. The user should be able to store any information in the leaves and the tree has some methods which get a set of user-defined values and need to access the corresponding leaves in constant time (not amortized). I came up with t

it1352 2 2019-05-13

Anonymous classes in C#

In C I can declare a fully functional anonymous class inside a piece of code where it's needed so that I don't have to declare it if I need it only once. The code should be like this Class MyClass { Class { String string1; String string2; void MyMethod(); } Strings; } And call it the members with MyClass.S

it1352 0 2020-10-02

c# abstract classes

i have to create a fake DMV program that calculates annual fees, for commercial and private vehicles. Those two classes will be abstract and they will polymophism from a class named all vehicles. My instructor wants only one object created the entire program(in main) but since my top 3 tier classes are abstract. I can't create an object with them

it1352 2 2019-05-10

Call a class inside another class in PHP

Hey there I'm wondering how this is done as when I try the following code inside a function of a class it produces some php error which I can't catch public $tasks; $this->tasks = new tasks($this); $this->tasks->test(); I don't know why the initiation of the class requires $this as a parameter either :S thanks class admin { functi

it1352 1 2019-05-13

how to create class variable dynamically in python

I need to make a bunch of class variables and I would like to do it by looping through a list like that: vars=('tx','ty','tz') #plus plenty more class Foo(): for v in vars: setattr(no_idea_what_should_go_here,v,0) is it possible? I don't want to make them for an instance (using self in the __init__) but as class variables. Solution

it1352 5 2019-05-13

nested classes in Python

Dealing with classes (nested etc) does not look easy in Python, surprisingly! The following problem appeared to me recently and took several hours (try, search ...) without success. I read most of SO related links but none of them has pointed the issue presented here! #------------------------------------ class A: def __init__(self):

it1352 2 2019-05-13

Pass this to base constructor

I am trying to implement good design patterns for a program I am writing. I have a class structure like this. abstract class SomeBase { public SomeObject obj { get; protected set; } protected SomeBase(SomeObject x) { obj = x; } //Other methods and fields... } public class SomeDerived : SomeBase { public

it1352 2 2020-08-19

Swift and using class extension

I don't understand why programmers use the extension keyword in their class implementation. You can read in other topics that code is then more semantically separated and etc. But when I work with my own code, it feels clearer to me to use // MARK - Something. Then when you use methods list (ctrl 6) in Xcode, everything is seen at first look. In A

it1352 0 2019-05-13