Questions tagged [return-type]
The return-type tag has no usage guidance.
52
questions
0
votes
1
answer
157
views
How to handle different json response for the same api rest endpoint and different http status
I have an endpoint similar to GET ../produtcs/123 where 123 stands for an ID. The REST service response
with either status 200 and a json object A {"deliveryData": {"status": 200, ...
2
votes
3
answers
675
views
Should my methods return concrete classes or interfaces?
I'm building a ASP.NET Core Web API and the application consists of 3 main modules.
Data module: Contains the entities and DbContext
Web API: Contains the controllers
Service module: Contains all the ...
10
votes
8
answers
4k
views
What is the purpose of enclosing all return values and arguments of a method in separate classes?
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(...
2
votes
2
answers
306
views
"Returns true if changed" pattern [closed]
The Collection interface in Java has, among others, these methods:
boolean add(E e)
boolean addAll(Collection<? extends E> c)
boolean remove(Object o)
boolean removeAll(Collection<?> c)
...
2
votes
1
answer
266
views
REST - different response from same resource dependent on requester
Let's say I have a single resource of employee that belongs to user:
{
"id": 1, "name": "John Doe", "userId: 1
}
When making a GET request to /employees/1, I'm ...
1
vote
2
answers
106
views
Good OO design pattern for variant return type needs
I've got a validation function something like this (pseudo-code):
public function validate(Thing thing) {
if (thing.a != "a") {
return false; // most of the time
}
if (...
8
votes
9
answers
9k
views
Returning true/nothing instead of true/false?
Is it OK to have a function that returns true/nothing instead of true/false?
My examples use JavaScript, but I'm wondering about the general case, not attached to one specific language.
The subjects ...
1
vote
1
answer
2k
views
UML - Overload operations with different parameters and a different return type
I would like to know if it is allowed in the UML to specify a different return type for overloaded operations. This is possible for methods in Java:
public class C
{
public int addOne(int a) {
...
0
votes
4
answers
147
views
Is there a pattern or best practice for returning dynamically typed data?
I have a method that returns the percentage change of a data in a certain period. After calling that method, i need to know if in the current period the data increased, decreased or is the same when ...
5
votes
2
answers
498
views
Class that returns multiple unrelated values, are there better way to accomplish this?
I have a "tracker" class. This class tracks objects from a given input image. But in addition to this, there is another parameter that corresponds to a value used in generating the image. The ...
0
votes
1
answer
2k
views
C# Unit Testing: Mock a Return Type
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 ...
3
votes
2
answers
234
views
Callback pattern - return value confusion
I have a ConstraintsResolver class which resolves a queue of Constraints. This is done when a ConstraintsResolver object calls meetConstraint() on a Constraint one.
Most of meetConstraint() ...
5
votes
3
answers
1k
views
In languages without exception-handling, should error codes be returned from the function or in function parameters?
I'm writing a CSV parsing library in C and am considering whether to express error codes as return values or as parameters passed by reference.
For example, here are the signatures for the function ...
9
votes
3
answers
4k
views
What do you need Covariant Return Types for?
In this article, it is written that in C# 8.0 new feature of convariant return type will be included as the community asking for this feature for quite a long time.
Can anybody explain why and when ...
60
votes
6
answers
39k
views
Why do many functions that return structures in C, actually return pointers to structures?
What is the advantage of returning a pointer to a structure as opposed to returning the whole structure in the return statement of the function?
I am talking about functions like fopen and other low ...