Tag Archives: class

(C#) LazyLoader – a simple, thread-safe class that can be used to load data on demand

A simple, thread-safe wrapper class for lazy-loading data into an instance on-demand (i.e. when the instance is first accessed.) Usage: LazyLoader l = new LazyLoader(() => Foo.LoadFromDataSource(“DB Connection String”)); // For access to the lazy-loaded instance: var x = l.Instance.Bar; // Need to ensure that the data is loaded deterministically? Use this: l.EnsureLoad();

Posted in C# | Also tagged , , , , , , , , | Leave a comment

LView – PHP View Class

View class that contains features like: – get vars inside the view with: 1) $var1 2) $this->var1 3) or $this->get( ‘var1′, ‘defaultValue’ ) – factory method for direct chaining: LView::factory( ‘test.php’ )->set( ‘var1′, ‘value1′ )->show(); – set filter callbacks that will be executed right after rendering – set global vars and global filters to be [...]

Posted in PHP | Also tagged , , , , , , , , | Leave a comment

(PHP) Login Class

Posted in PHP | Also tagged , , | Leave a comment

Exception handling in PHP

PHP5 supports exception handling with try and catch blocks. This can be used to notify the user of any exceptions. This example uses a modified version of the Person class of the Inheritance in PHP example to throw an exception if an invalid age has been supplied. The catch block is used to catch the [...]

Posted in PHP | Also tagged , , , , , , , | Leave a comment

2D and 3D vector normalization and angle calculation in C++

Normalizing a vector can derive the direction of the vector in 2D or 3D space. A normalized vector is also known as a unit vector. We’re going to normalize and calculate the angles of a 2D vector at position (5,5) and a 3D vector at position (5,5,5). This can come in very handy when, for [...]

Posted in C++ | Also tagged , , , , , , , , , , , , , , , , , , , , , , , | 2 Comments

Classes in C++

C++ can be used for object-oriented programming. This example shows you how to define a class and a header file belonging to it.

Posted in C++ | Also tagged , , , , , , , | Leave a comment

Inheritance in PHP

Classes can contain subclasses and subclasses can in turn contain superclasses. For example, the class Person could be the superclass of the class PizzaDeliveryGuy.

Posted in PHP | Also tagged , , , , , , , , , , , | Leave a comment

Properties in C#

Properties in C# can be used to set or get the value of an attribute. Suppose you have a class called Person which has the attributes name and age. class Person { String name; int age; public Person(String name, int age){ this.name = name; this.age = age; } } The attributes of the Person class [...]

Posted in C# | Also tagged , , , , , | Leave a comment

Constructors and destructors in PHP

You might want to execute code when an instance of an object gets constructed or destructed. PHP offers constructors and destructors for this purpose. A constructor can be created by declaring a function called __construct within a class and a destructor can in turn be created by declaring a function called __destruct. <?php class Foo [...]

Posted in PHP | Also tagged , , , , , , | Leave a comment