New answers tagged class
0 votes
Is there a way in a class function to return an instance of the class itself?
I had exactly this problem today and found that this works: from __future__ import annotations class a(type): def __init__(self, n): self.n = n def foo() -> a: return a(...
Best practices
0 votes
0 replies
0 views
0 votes
Multi-select individuals and assign a class in Protege
There is unforetunately no way to achieve this in Protege. You will have to assign the class for each individual.
Best practices
1 vote
0 replies
0 views
Class inheritence vs one class being element of the another
It's been a few decades since I programmed in C++, but as far as I recall, C++ allows multiple inheritance. Most other languages, like Java or C#, only allow single inheritance. If for no other ...
Best practices
1 vote
0 replies
0 views
Class inheritence vs one class being element of the another
This is the old 'is-a' versus 'has-a' question. Only you can answer it, for your two specific classes. Is B a kind of A? or does A just have-a B? Is class B really a subtype of class A? or is it just ...
Advice
0 votes
0 replies
0 views
Review of my UML class diagram for a student social network (database design)
I don't see too much non-French here. A lot of these terms are written the same in English and French. For as far as I can see this is a fully French model. That is also a bit of a problem, since the ...
Advice
0 votes
0 replies
0 views
Review of my UML class diagram for a student social network (database design)
What you should fix first of all, is that mixture of French and English in your naming of entities and properties.
Advice
0 votes
0 replies
0 views
Review of my UML class diagram for a student social network (database design)
You should design the database before the software's class structure. Currently, you're missing keys/ids for many of your objects-- but the importance of this depends on what you plan to use the ...
2 votes
Accepted
Create a custom cast (that also accepts $null)
tl;dr You can only achieve what you want via a constructor, not also with a cast. Thus, your only options are: # Method syntax [Checkbox]::new($null).ToString() # New-Object alternative (more ...
0 votes
Why would I use an ID selector instead of a class?
The other differences are already answered but I also want to add one which is not listed in this answer lists and that is: - IDs in HTML can also be used to create bookmarks (fragment navigation) ...
1 vote
Undefined symbols for architecture x86_64: "operator<<"
I have just had the exact same issue, and seeing as this question, which is as yet unanswered, helped me see the issue, I decided to post an answer. For hours I just could not see what my particular ...
Best practices
1 vote
0 replies
0 views
Indicate to Python user that the __init__ constructor should only be used by the class
For reasons I don't want to get into, Okay, let's play a guessing game...
Best practices
0 votes
0 replies
0 views
Indicate to Python user that the __init__ constructor should only be used by the class
You could leave __init__ as I have defined it so that it cannot be called. Take what you would have wanted to put in __init__ in a new function _init: lass MyClass(): def __init__(self): ...
Best practices
0 votes
0 replies
0 views
Indicate to Python user that the __init__ constructor should only be used by the class
I do need to use __init__ internally however, so I do need to parse the error with a kwarg as in the other answers.
Best practices
1 vote
0 replies
0 views
Indicate to Python user that the __init__ constructor should only be used by the class
Verified that it creates a new class each time: def init_from(c): class MyClass: def __init__(self, a, b): self._a = a self._b = b return MyClass(c-3, c+3) x1 =...
Best practices
0 votes
0 replies
0 views
Indicate to Python user that the __init__ constructor should only be used by the class
Doesn't this create a new version of the MyClass class every time you call init_from?
Best practices
0 votes
0 replies
0 views
Indicate to Python user that the __init__ constructor should only be used by the class
The other answers are probably the best pythonic practice. but if you really want to enforce the caller, you can try using the inspect feature to verify the caller's stack frame: #!/usr/bin/env ...
Best practices
2 votes
0 replies
0 views
Indicate to Python user that the __init__ constructor should only be used by the class
You can hide the whole class inside a factory function: def init_from(c): class MyClass(): a = None b = None def __init__(self, a, b): self.a = a ...
Best practices
3 votes
0 replies
0 views
Indicate to Python user that the __init__ constructor should only be used by the class
You cannot prevent someone from calling obj = MyClass(), but you can raise an exception if somebody does. You can by pass calling the __init__ method as follows: class MyClass(): def __init__(self)...
Best practices
2 votes
0 replies
0 views
Indicate to Python user that the __init__ constructor should only be used by the class
you can only disable it by passing False as keyword argument and and True keyword argument in your @classmethod definition class MyClass: def __init__(self, value, _from_factory=False): # ...
Best practices
2 votes
0 replies
0 views
Indicate to Python user that the __init__ constructor should only be used by the class
__init__ always exists and you can't hide it. What I'd do is add a kwarg __private, which defaults to false throws an exception if it's false. Within your own classes factory methods, you then just ...
0 votes
Run Pytest Classes in Custom Order
It might be a personal preference, but I find this structure easier to understand and modify. You can assign an integer to each test, depending on the method name, class name, or file name. The tests ...
0 votes
Fields in Scala Constructor
Yes, there is a small difference. class Days(days: AnyVal): val n: AnyVal = days days is just a constructor parameter. You manually define n as a fields. Only n is accessible from outside. class ...
0 votes
ArrayList error, Exception in thread "main" java.lang.NullPointerException
Initialize your list Perhaps you neglected to establish an empty list to hold your destinations. In this example, we use new ArrayList<>() to establish a new empty list on the same line where we ...
-2 votes
ArrayList error, Exception in thread "main" java.lang.NullPointerException
Array list is part of the java.util package and implements the List interface. The difference between a built-in array and an ArrayList in Java, is that the size of an array cannot be modified (if you ...
Top 50 recent answers are included
Related Tags
class × 79813python × 15969
c++ × 15931
java × 12186
oop × 7016
php × 6931
c# × 6870
object × 6094
javascript × 5672
methods × 4765
inheritance × 4062
function × 3647
arrays × 3153
python-3.x × 2793
constructor × 2583
jquery × 1974
android × 1922
variables × 1885
list × 1670
html × 1556
instance × 1480
css × 1449
templates × 1382
static × 1381
pointers × 1345