Skip to main content

Questions tagged [methods]

A method is a procedure that is associated with a particular object. The purpose of the method is to guide the behavior of the object, and the tag should be used when this is the case.

Filter by
Sorted by
Tagged with
-4 votes
2 answers
342 views

I have a method like this private void foo() { this.myValue = readSomeValueFromFileSystem() } What is the good name for that ? Is there any convention about it ? I feel that it is kinda set but ...
gstackoverflow's user avatar
17 votes
8 answers
5k views

When is it better to pass data to a function in a parameter, and when is it better for the function to just fetch the data itself? Here's some simplified examples in PowerShell: Option 1 (give the ...
Nova's user avatar
  • 181
6 votes
4 answers
3k views

Uncle Bob mentions in his book "Clean Code" that "[f]unctions should do one thing [...] only" and advocates that a method should stick to one abstraction level (I'd call it flight ...
Christian's user avatar
  • 171
1 vote
2 answers
359 views

I'm writing a C++ class, CBookSpellDef which has the following methods: int GetIndexOf(const char *psz); char* GetNameAtIndex(int index) { return m_spellTypes[index].szName; } char* ...
Bunabyte's user avatar
  • 643
-4 votes
1 answer
119 views

Courtesy link: What Are The Specific Meanings Of The Terms: Functions, Methods, Procedures, and Subroutines? What's the difference between a function and a method? In the linked question: function,...
Arunabh's user avatar
13 votes
4 answers
5k views

Let's say that I have a class called Mission. This class is intended to represent a mission requested by a professor working in a faculty. Mission has a private enum field representing whether the ...
Mehdi Charife's user avatar
1 vote
2 answers
802 views

I know there are some questions about "Introduce parameter object", eg: Is "Introduce Parameter Object" actually a good pattern?, Should we avoid custom objects as parameters?, ...
wcminipgasker2023's user avatar
1 vote
1 answer
956 views

There is a variable that must persist between calls but otherwise only one method uses it. As it is a method of the object, the value can be persisted as a private field of the object, or otherwise it ...
h22's user avatar
  • 966
-1 votes
1 answer
137 views

When writing code in a programming language that has the option of creating standalone functions vs. methods of a class or struct, what is the most relevant objectively-quantifiable reason to choose ...
MikeSchinkel's user avatar
10 votes
8 answers
4k views

I've seen such a convention. Whenever a public method is declared, two classes are also defined that enclose its return value and parameters like this: public MethodNameReturnDTO MethodName(...
gaazkam's user avatar
  • 4,529
1 vote
2 answers
517 views

I don't know from where I got this but in my head a function returns a value and a method does not. I know that with OOP a method is a function related to a class. But I am trying to remember where I ...
houimli manel's user avatar
-2 votes
1 answer
334 views

With the introduction of the slash character to specify position-only arguments, is it recommended to put a slash in every method after the self parameter? For example: class A: def something(self,...
Billy's user avatar
  • 99
0 votes
1 answer
165 views

Sometimes I need to use the same use case with different details implementation. It is easy and straightforward for presenters as each use case has its own output port and therefore different ...
Mohammad Alotol's user avatar
-1 votes
1 answer
2k views

Here's what I'd like to do in the form of working code, since it's difficult for me to explain otherwise: from typing import Callable, Generic, TypeVar from typing_extensions import Self # The type ...
lapraswastaken's user avatar
-1 votes
1 answer
455 views

I have a method, that takes a list of students, and returns the student with the best score. Part of me wants to call it Student getBestStudent(List<Student> students), but I think that get ...
a3dsfcv's user avatar
  • 131
2 votes
5 answers
2k views

I am relatively new to C# and OOP concepts in general, but am building a standalone application and have run into a question and want to make sure I'm doing it the "right way". I have a few ...
adc395's user avatar
  • 39
0 votes
2 answers
121 views

Here are a couple of examples in Python: clearly_even = 2 * get_integer() print(solve_for_any_integer(clearly_even)) def solve_for_any_integer(x): while x % 2 == 1: x = make_even_from_odd(x) ...
George Sovetov's user avatar
-2 votes
1 answer
173 views

I am currently trying to name a method that prepares/alters some input data, then passes it on, and I'm wondering if there is a naming scheme for such methods. Concretely, I have a reusable UI ...
BlackWolf's user avatar
4 votes
1 answer
93 views

In the UML specification 2.5.1 (Link) on page 117 it is specified that the notation of operations (methods) should look like the following: [<visibility>] <name> ‘(‘ [<parameter-list>...
Raphael's user avatar
  • 151
1 vote
5 answers
439 views

I have a abstract class named MotorizedVehicle that contains an implemented gas- and brake-function. I want to make a Truck class that extends this class and uses gas exactly in the same way as ...
Felix Jönsson's user avatar
18 votes
9 answers
5k views

I am trying to create an object model for a user and a chatroom. I'm stuck on where to place certain functionality when the objects collaborate. At the moment all the functionality for the User is ...
user avatar
0 votes
2 answers
190 views

We've been battling over where certain methods should live within our domain model, so looking for some adice and reasoning as to where they should go. Say we have a Project object now that Project ...
Gaz's user avatar
  • 159
1 vote
2 answers
162 views

This may be too general of a question, but basically whenever I try to find an answer for something that would work from a Javascript approach, the answer heavily implies that you wouldn't do it that ...
sheepdeets's user avatar
2 votes
2 answers
854 views

C++ only supports single dynamic dispatch methods. Indeed, the following program: #include <iostream> struct Shape { virtual void overlap(Shape* y) { std::cout << "Shape, Shape\n&...
Géry Ogam's user avatar
0 votes
2 answers
5k views

I am studying the programming language Kotlin, and I just came across the idea of a Data Class. I have a background in Java programming where classes can have fields and methods. I have heard ...
Steve T's user avatar
  • 141
6 votes
4 answers
2k views

HTTP has safe and idempotent HTTP-methods. Idempotence in HTTP is not exactly the same as idempotence in mathematics, the definition states: Methods can also have the property of "idempotence&...
Martin Fürholz's user avatar
-3 votes
2 answers
79 views

When a method is called and must return a value for further processing, but for instance a message has also to be provided to the UI : what is the best or most common way to deal with those 2 outputs ...
Rabskatran's user avatar
  • 1,421
1 vote
2 answers
214 views

I can't wrap my head around this statement here: One common drawback of using composition instead of inheritance is that methods being provided by individual components may have to be ...
asds_asds's user avatar
  • 119
9 votes
6 answers
3k views

I use Python but I guess my question applies to OOP in general. Whenever I create a class I am never sure whether I should put a parameter/attribute in the constructor or in the method the parameter ...
Andy Gondzer's user avatar
1 vote
1 answer
2k views

Please consider the following code: class baseclass { public $hideme; public function getit() { return $this->hideme; } public function setit($value) { $this->hideme = $value; } } ...
user106313's user avatar
4 votes
4 answers
379 views

We have multiple pages searching for users, each site having different search parameters. Sometimes, we have 2 parameters, sometimes 4 and most of these parameters overlap. So we have kind of (...
Chrᴉz remembers Monica's user avatar
9 votes
3 answers
9k views

What does it mean when you say that a method or a function should do only one thing? Can it do a few things as long as it has a cohesive name? Should we avoid routines with the word "and" in them? ...
Piovezan's user avatar
  • 481
4 votes
2 answers
3k views

I am a Java dev for almost all of my programming (at least in the workplace) but I do some Unity for fun on the side. I have used C# properties many times and they are convenient to still provide ...
JaredSK74's user avatar
1 vote
1 answer
1k views

Here are two endpoints (or methods): ListResources(user_id) - Fetch the resources based on the given user id. SearchResources(query_options) - Fetch the resources with specified conditions. The ...
Yami Odymel's user avatar
3 votes
5 answers
12k views

I wanted to follow up on this previous question I asked related to @Laive comment, but I couldn't think of an excellent way to do so without asking another question, so here we go. With the previous ...
Ertai87's user avatar
  • 187
2 votes
2 answers
232 views

Suppose I have the following methods: def read(file: str) -> List[str]: temp = [] with open(file) as f_obj: for line in f_obj: temp.append(line) return temp def ...
user avatar
7 votes
2 answers
2k views

My question regards the use of import statements. In most programming languages I've come across (e.g. Python, Scala, Go), it is necessary to first import a library before you can use its functions. ...
NieuweNils's user avatar
6 votes
3 answers
13k views

Assume I have the following method that does the same logic but deals with different objects (It's more a pseudocode): private <E> List<E> updateOrInsert(List<E> list) { if (...
hb0009's user avatar
  • 71
2 votes
1 answer
2k views

I am trying to find out if it is allowed in the UML to change the visibility (access modifier) of an operation when overriding it. For example, in Java it is possible to increase the visibility of an ...
xoric's user avatar
  • 51
13 votes
3 answers
3k views

Some base points: Python method calls are "expensive" due to its interpreted nature. In theory, if your code is simple enough, breaking down Python code has negative impact besides readability and ...
lucasgcb's user avatar
  • 375
4 votes
2 answers
223 views

For example, suppose my input data and UI is not in 1 to 1 relationship: html: <script> aChanged=function(){ }; bChanged=function(){ }; cChanged=function(){ }; </script> a:<input id="...
ocomfd's user avatar
  • 5,760
15 votes
5 answers
5k views

I have a method that creates a data file after talking to a digital board: CreateDataFile(IFileAccess boardFileAccess, IMeasurer boardMeasurer) Here boardFileAccess and boardMeasurer are the same ...
pavuxun's user avatar
  • 281
1 vote
4 answers
883 views

I was reading here about OOP and methods, and the accepted answer states that method names should be verbs. However, that doesn't really answer my question. Suppose if I had a Character class with a ...
user avatar
2 votes
1 answer
1k views

I have an arbitrary number of derived classes all inheriting from the same base class. These derived classes all have the same static variables and static methods, although the implementations may ...
Inertial Ignorance's user avatar
13 votes
7 answers
9k views

Here's what I mean: class MyClass { int arr1[100]; int arr2[100]; int len = 100; void add(int* x1, int* x2, int size) { for (int i = 0; i < size; i++) { x1[i] +...
Ethan Lipson's user avatar
0 votes
1 answer
2k views

What is the best way to Mock a return type if we don't care about the actual state of the object. For example, I am Mocking a method whose return type is: IEnumerable<Document> Now, I can add ...
Shamim Hafiz - MSFT's user avatar
0 votes
1 answer
338 views

Trying to figure out which structure is cleaner between using a specialized function or using parameters to accomplish the same thing (see code example below). Essentially, I can reduce the number of ...
Nick Sweet's user avatar
0 votes
4 answers
944 views

I want to move a bunch of similar methods to an external class. The class is initialized with the original class instance. From there I can access it either by property (persistent instance) or by ...
Jack's user avatar
  • 111
1 vote
1 answer
2k views

Is there a generally accepted term for a method that does nothing more than calling another method (and returning its result)?
bvgheluwe's user avatar
  • 1,187
42 votes
6 answers
58k views

Context: I am currently working on a small project in Python. I commonly structure my classes with some public methods that are documented but mainly deal with the high level concepts (what a user of ...
Serge Ballesta's user avatar

1
2 3 4 5