Tutorial by Examples: class

class sample{ public static function add_action_func(){ //note __CLASS__ will also include any namespacing add_action('init', array(__CLASS__, 'samp') ); } public static function samp(){ echo 'i did something'; } } sample::add_a...
Consider the utility class pattern: a class with only static methods and no fields. It's recommended to prevent instantiation of such classes by adding a private a constructor. This live template example makes it easy to add a private constructor to an existing class, using the name of the enclos...
Unlike a named class or struct, unnamed classes and structs must be instantiated where they are defined, and cannot have constructors or destructors. struct { int foo; double bar; } foobar; foobar.foo = 5; foobar.bar = 4.0; class { int baz; public: int buzz; ...
mutable modifier in this context is used to indicate that a data field of a const object may be modified without affecting the externally-visible state of the object. If you are thinking about caching a result of expensive computation, you should probably use this keyword. If you have a lock (for ...
class API { public: static API& instance(); virtual ~API() {} virtual const char* func1() = 0; virtual void func2() = 0; protected: API() {} API(const API&) = delete; API& operator=(const API&) = delete; }; class WindowsAPI ...
An immutable object is an object whose state cannot be changed. An immutable class is a class whose instances are immutable by design, and implementation. The Java class which is most commonly presented as an example of immutability is java.lang.String. The following is a stereotypical example: ...
Enums in Swift are much more powerful than some of their counterparts in other languages, such as C. They share many features with classes and structs, such as defining initialisers, computed properties, instance methods, protocol conformances and extensions. protocol ChangesDirection { mutati...
Note: Everything below applies to the str.format method, as well as the format function. In the text below, the two are interchangeable. For every value which is passed to the format function, Python looks for a __format__ method for that argument. Your own custom class can therefore have th...
A protocol may specify that only a class can implement it through using the class keyword in its inheritance list. This keyword must appear before any other inherited protocols in this list. protocol ClassOnlyProtocol: class, SomeOtherProtocol { // Protocol requirements } If a non-class typ...
With Gson, you can read JSON dataset and map them to a custom class MyClass. Since Gson is not serializable, each executor needs its own Gson object. Also, MyClass must be serializable in order to pass it between executors. Note that the file(s) that is offered as a json file is not a typical JSON...
References to class declarations are typed Class: var spriteClass:Class = Sprite; You can use variables typed Class to instantiate instances of that class: var sprite:Sprite = new spriteClass(); This can be useful for passing an argument of type Class to a function that might create and inst...
The most important AppWidgetProvider callback is onUpdate(). It is called everytime an appwidget is added. public class ExampleAppWidgetProvider extends AppWidgetProvider { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { final int N = a...
Provided an App.GoogleMap coffee script class, the google map can be initialized like this: # app/assets/javascripts/google_maps.js.coffee # ... class App.GoogleMap map_div: {} map: {} constructor: (map_div)-> @map_div = map_div @init_map() @reference_the_map_as_dat...
Provided an App.GoogleMap coffee script class and the marker information being stored in the data-address-fields attribute of the .google_map div, the map markers can be initialized on the map like this: # app/assets/javascripts/google_maps.js.coffee # ... class App.GoogleMap # ... markers:...
Provided an App.GoogleMap coffee script class with the google.maps.Map stored as @map and the google.maps.Markers stored as @markers, the map can be auto-zoomed, i.e. adjusted that all markers are visible, like this: on the map like this: # app/assets/javascripts/google_maps.js.coffee # ... cla...
Add below to your build.gradle out of android tag: // Apply plug-in to app. apply plugin: 'com.google.gms.google-services' Add below helper class to your util package: /** * Created by Andy */ public class GoogleSignInHelper implements GoogleApiClient.OnConnectionFailedListener, ...
You can get a Model class from a Controller name this way (context is Controller class): class MyModelController < ActionController::Base # Returns corresponding model class for this controller # @return [ActiveRecord::Base] def corresponding_model_class # ... add some validation...
Instantiating a socket can be done in various ways. by 2 line declaration & instantiation: First we need to define a variable which will hold a Socket class object: Socket socket; then we can create a Socket class object: socket = new Socket(); We can also make a one line defin...
.message color: white .message-important @extend .message background-color: red This will take all of the styles from .message and add them to .message-important. It generates the following CSS: .message, .message-important { color: white; } .message-important { background-...
.message color: white .important background-color: red .message-important @extend .message, .important In the above code @extend is used in one line to add multiple classes' code to .message-important, however, it is possible to use one extend per line like this: .message-importan...

Page 9 of 28