Tutorial by Examples: classes

When inheriting from any base class, only one partial class needs to have the base class specified. // PartialClass1.cs public partial class PartialClass : BaseClass {} // PartialClass2.cs public partial class PartialClass {} You can specify the same base class in more than one partial clas...
public static void main(String[] args) throws Exception { File jarFile = new File("Input.jar"); Map<String, ClassNode> nodes = JarUtils.loadClasses(jarFile); Map<String, byte[]> out = JarUtils.loadNonClassEntries(jarFile); Map<String, String> map...
Anonymous classes were introduced into PHP 7 to enable for quick one-off objects to be easily created. They can take constructor arguments, extend other classes, implement interfaces, and use traits just like normal classes can. In its most basic form, an anonymous class looks like the following: ...
import java.util.ArrayList; import java.util.List; import static java.lang.System.out; public class PolymorphismDemo { public static void main(String[] args) { List<FlyingMachine> machines = new ArrayList<FlyingMachine>(); machines.add(new FlyingMachine())...
abstract class Machine { constructor(public manufacturer: string) { } // An abstract class can define methods of it's own, or... summary(): string { return `${this.manufacturer} makes this machine.`; } // Require inheriting classes to implement methods ...
If you want your application to support a plug-in system, for example to load plug-ins from assemblies located in plugins folder: interface IPlugin { string PluginDescription { get; } void DoWork(); } This class would be located in a separate dll class HelloPlugin : IPlugin { ...
Inherits Specifies the base (or parent) class Public Class Person End Class Public Class Customer Inherits Person End Class 'One line notation Public Class Student : Inherits Person End Class Possible objects: Dim p As New Person Dim c As New Customer Dim s As New Student ...
Singleton classes share their instance/class variables with their object. class Example @@foo = :example end def Example.foo class_variable_get :@@foo end Example.foo #=> :example class Example def initialize @foo = 1 end def foo @foo end end e = Ex...
Overall the easiest way to work with JSON is to have a case class mapping directly to the JSON (same fields name, equivalent types, etc.). case class Person( name: String, age: Int, hobbies: Seq[String], pet: Pet ) case class Pet( name: String, `type`: String ) // these...
The practice of replacing an object with a test double that verifies expectations, for instance asserting that a method has been called, is referred to as mocking. Lets assume we have SomeService to test. class SomeService { private $repository; public function __construct(Repository $r...
One of the most common obstacles using classes is finding the proper approach to handle private states. There are 4 common solutions for handling private states: Using Symbols Symbols are new primitive type introduced on in ES2015, as defined at MDN A symbol is a unique and immutable data typ...
Angular also provides some CSS classes for forms and inputs depending on their state ClassDescriptionng-touchedField has been touchedng-untouchedField has not been touchedng-pristineField has not been modifiedng-dirtyField has been modifiedng-validField is validng-invalidField is invalid You can u...
Though the transaction class method is called on some ActiveRecord class, the objects within the transaction block need not all be instances of that class. This is because transactions are per-database connection, not per-model. In this example a balance record is transactionally saved even though ...
Bootstrap provides multiple classes for styling buttons and making them stand out. Bootstrap buttons can be created by adding the .btn class to an element. Bootstrap ClassRole (color).btn-defaultStandard button (white).btn-primaryProvides extra visual weight and identifies the primary action (blue...
There are three ways to reopen a Singleton Class Using class_eval on a singleton class. Using class << block. Using def to define a method on the object's singleton class directly class Example end Example.singleton_class.class_eval do def foo :foo end end Example.fo...
All objects are instances of a class. However, that is not the whole truth. In Ruby, every object also has a somewhat hidden singleton class. This is what allows methods to be defined on individual objects. The singleton class sits between the object itself and its actual class, so all methods defi...
POSIX character classes are predefined sequences for a certain set of characters. Character classDescription[:alpha:]Alphabetic characters[:alnum:]Alphabetic characters and digits[:digit:]Digits[:xdigit:]Hexadecimal digits[:blank:]Space and Tab[:cntrl:]Control characters[:graph:]Visible characters ...
Partial classes provide a clean way to separate core logic of your scripts from platform specific methods. Partial classes and methods are marked with the keyword partial. This signals the compiler to leave the class "open" and look in other files for the rest of the implementation. // E...
CoffeeScript provides a basic class structure that allows you to name your class, set the superclass, assign prototypal properties, and define the constructor, in a single assignable expression. Small example below: class Animal constructor: (@name) -> move: (meters) -> alert @n...
An anonymous inner class is a form of inner class that is declared and instantiated with a single statement. As a consequence, there is no name for the class that can be used elsewhere in the program; i.e. it is anonymous. Anonymous classes are typically used in situations where you need to be abl...

Page 4 of 6