Questions tagged [methods]

A method is a block of code that performs a task and is associated with a class or an object. It is related to the non-object-oriented concepts of functions and procedures.

A method is a code block that contains a series of statements. A program causes the statements to be executed by calling the method and specifying any required method arguments.

In object-oriented programming, a method is a subroutine (or procedure) associated with a class. Methods define the behavior to be exhibited by instances of the associated class at program run time.

Methods have the special property that at runtime, they have access to data stored in an instance of the class (or class instance or class object or object) they are associated with and are thereby able to control the state of the instance.

The association between class and method is called binding. A method associated with a class is said to be bound to the class. Methods can be bound to a class at compile time (static binding) or to an object at runtime (dynamic binding).

Common features

They have few things in common:

  1. They may take some parameters / arguments for their processing.
  2. They may have a return-value, that returns some value to the calling method.
  3. The concept of and is also associated with methods.

References

Also see:

30291 questions
6
votes
2 answers

declare parameter subtype in Java interface, use subtypes in Java implementing methods

I want to declare a method in an interface where the parameter of the method defined in implementing classes can be a subtype of a specific java class for example: interface Processor{ processRequest( Request r); } public class SpecialRequest…
user592672
  • 61
  • 2
6
votes
2 answers

What add to controller and what to models

I have a little problem. What data keep in controllers and what in models? I know in models keep whole logic of applications etc, but what's query and helpers functions? for example Controller: public function add(Request $request) { $item = new…
Piffek
  • 89
  • 1
  • 7
6
votes
3 answers

Can I inline static class methods in Objective-C?

You can declare functions as inlines like this: #ifdef DEBUG void DPrintf(NSString *fmt,...); #else inline void DPrintf(NSString *fmt,...) {} #endif so that when you're not in DEBUG, there's no cost to the function because it's optimized and…
Jonas Anderson
  • 1,987
  • 4
  • 24
  • 28
6
votes
3 answers

How to select which overloaded version of a method to call without using a cast?

i have a question to Java Overload Methods. Suppose i have an overload methods foo: public static String foo(String x) { return "foo-String: " + x; } public static String foo(Object x) { return "foo-Object: " + x; } How can I implement to…
Aiko West
  • 791
  • 1
  • 10
  • 30
6
votes
2 answers

Is it possible to finalize a virtual method in C#?

By that I mean, it is possible to mark a virtual method in C# as final so no other types deriving from this type, can override it ever again?
Joan Venge
  • 315,713
  • 212
  • 479
  • 689
6
votes
1 answer

How to check if object supports method in vba?

Is it possible to check whether an object supports a certain method without an error handler in VBA? I've found numerous duplicates asking the question for for example JavaScript and Symphony2, but not yet in VBA. I would like to use a .sendkeys…
a.t.
  • 2,002
  • 3
  • 26
  • 66
6
votes
2 answers

How do I specify a function's type/signature in Julia?

I'm implementing Newton's method for finding roots in a precompiled library. The common case will be to work with functions from Float64 to Float64, and I want an optimized compiled version of it to exist in the library. I will, of course, implement…
Sean Lake
  • 578
  • 2
  • 8
  • 14
6
votes
3 answers

My object is not updated even if I use the pointer to a type to update it

I store some Individual objects in a slice. Before appending it to the slice I print the name of the Individual object. After I have stored it in the slice, I then retrieve it as a pointer and want to change the name to "Peter", but the change does…
Rox
  • 2,647
  • 15
  • 50
  • 85
6
votes
1 answer

Best practice for defining S3 methods with different arguments

I am in the process of adding a standard S3 method dispatch system to my package (OneR) where I have one method for data frames and one for formulas. The problem I have is that I have different arguments for both methods. I don't need the data…
vonjd
  • 4,202
  • 3
  • 44
  • 68
6
votes
1 answer

How can I retrieve the methods of a Julia macro?

In Julia, the methods function may be used to retrieve the methods of a function. julia> f(::Int) = 0 f (generic function with 1 method) julia> f(::String) = "" f (generic function with 2 methods) julia> methods(f) # 2 methods for generic function…
Harrison Grodin
  • 2,253
  • 2
  • 19
  • 30
6
votes
1 answer

Why do I have to declare methods outside a struct in Rust?

Why are methods created outside the struct? In languages like C#, you can add the methods inside the struct. I know that in languages like C and C++ you have header files so it makes sense, but as far as I know I can't create header files in Rust.
Pepernoot
  • 3,409
  • 3
  • 21
  • 46
6
votes
1 answer

How to call method by its string name with string struct name?

I have one struct with 2 methods under struct definition, I want to call in other place that use struct's name and method's name as param. Struct code as following: type ArticleForm struct { Name string `required:"true"…
user3818534
  • 61
  • 1
  • 1
  • 2
6
votes
1 answer

Swift method documentation - not showing in autocomplete

I am documenting my Swift methods as follows: /// Extracts the server time from the API call response. /// - parameter response: The HTTPURLResponse from which to extract the date. /// - returns: The 'Date' header from the response, as a `Date`…
Jacob King
  • 6,025
  • 4
  • 27
  • 45
6
votes
5 answers

How to call a template method?

There are a lot of online documents explaining how to write template methods, but not much example about how to call them, how to use them in code. I have a template method like this: VectorConvertor.h template static void…
hkBattousai
  • 10,583
  • 18
  • 76
  • 124
6
votes
1 answer

java design: repetitive methods of sub-objects

When I was working on a project of mine and had to use a lot of nested objects, I became very unsure of my design of structure in Java when I wanted to set an instance variable of a deeply nested object from the upper object. It feels like I miss a…
lokipoki
  • 63
  • 4
1 2 3
99
100