Private methods in Python

Python doesn’t have the concept of private methods or attributes. It’s all about how you implement your class. But you can use pseudo-private variables (name mangling); any variable preceded by __(two underscores) becomes a pseudo-private variable. From the documentation: Since there is a valid use-case for class-private members (namely to avoid name clashes of names … Read more

How to call C++ static method

Use :: instead of . MyObject o = MyMath::calcSomething(); When you are calling the method without the object of the class you should use :: notation. You may also call static method via class objects or pointers to them, in this case you should use usual . or -> notation: MyObject obj; MyObject* p = … Read more

@staticmethod vs @classmethod in Python

Maybe a bit of example code will help: Notice the difference in the call signatures of foo, class_foo and static_foo: class A(object): def foo(self, x): print(f”executing foo({self}, {x})”) @classmethod def class_foo(cls, x): print(f”executing class_foo({cls}, {x})”) @staticmethod def static_foo(x): print(f”executing static_foo({x})”) a = A() Below is the usual way an object instance calls a method. The … Read more

Accessing SharedPreferences through static methods

Cristian’s answer is good, but if you want to be able to access your shared preferences from everywhere the right way would be: Create a subclass of Application, e.g. public class MyApp extends Application {… Set the android:name attribute of your <application> tag in the AndroidManifest.xml to point to your new class, e.g. android:name=”MyApp” (so … Read more

How to mock with static methods?

Yes, you use instance methods. Static methods basically say, “There is one way to accomplish this functionality – it’s not polymorphic.” Mocking relies on polymorphism. Now, if your static methods logically don’t care about what implementation you’re using, they might be able to take the interfaces as parameters, or perhaps work without interacting with state … Read more

Swift Declare Class Func in Protocol

You can review Apple’s Documentation (subsection Method Requirements). There says: As with type property requirements, you always prefix type method requirements with the static keyword when they are defined in a protocol. This is true even though type method requirements are prefixed with the class or static keyword when implemented by a class In practice, … Read more

Access to static properties via this.constructor in typescript

but in typescript this.constructor.prop causes error “TS2339: Property ‘prop’ does not exist on type ‘Function’”. Typescript does not infer the type of constructor to be anything beyond Function (after all … the constructor might be a sub class). So use an assertion: class SomeClass { static prop = 123; method() { (this.constructor as typeof SomeClass).prop; … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)