Skip to main content

Questions tagged [constructors]

Member functions of a class which initializes objects of the given class.

4 votes
4 answers
467 views

Microsoft identifies dependency injection as one of the uses for primary constructors. public class ExampleController(IService service) : ControllerBase { [HttpGet] public ActionResult<...
Jannick Breunis's user avatar
0 votes
1 answer
193 views

While writing the constructor for class A in Python, I calculate some of the class's fields using function fun(). This function is never used outside the constructor of instances of this class. In ...
Harm van den Brand's user avatar
3 votes
3 answers
561 views

I am trying to explain and understand a way to create object which cannot have "default" instances. Typically I want classes which represent, as closely as possible, the real-life concept I ...
Patrick Wright's user avatar
-2 votes
3 answers
235 views

Context: 128kB RAM, freeRTOS. Considered solutions: Exceptions. Discouraged by both the memory size and the code style guide. Late bool init(...);. Has worked for a decade but has it's problems - can ...
Vorac's user avatar
  • 7,189
2 votes
5 answers
657 views

It recently came to my attention that its best practice to avoid database calls in constructors. I feel like this means you end up repeating unnecessary code, thus the code is less DRY? For example, ...
pooteeweet's user avatar
-1 votes
1 answer
214 views

I have a C++ library that I'm converting to Python. In the C++ library I have multiple constructors and many different types of conversion functions (think radians to degrees, and different types of ...
Krupip's user avatar
  • 1,347
1 vote
2 answers
516 views

A typical introductory example to OOP, classes, and constructors is object Car, with properties such as float fuel, bool is_engine_running, etc etc, and a class and constructor definition might be as ...
SRSR333's user avatar
  • 335
-1 votes
3 answers
661 views

My SmsRecipientDetails class constructor accepts String value as recipient phone number. I would like to accept number with spaces: assertDoesNotThrow(() -> new SmsRecipientDetails("123456789 &...
jnemecz's user avatar
  • 299

15 30 50 per page
1
2 3 4 5
11