C#: Accessing methods using dot

This entry is part 14 of 71 in the series C#

Accessing a member function or method using dot is a simple and yet important concept in object-oriented programming.

In traditional procedural programming, we would access the function directly.  Now we create an instance of a class called output and use it to access the method displayname in the class.

Program output = new Program();

Those member functions in a class are call methods in OOP.

using System;

namespace Hello
{
    class Program
    {
        public void displayname()
        {
            string name;

            Console.WriteLine("Hello, what is your name?");
            name = Console.ReadLine();
            Console.WriteLine("Your name is " + name);
            Console.ReadLine();
        }

        static void Main()
        {
            Program output = new Program();
            output.displayname();
        }
    }
}

In the example above, I have created a method call displayname and I put that as a public function since at this moment I am not too concern about protecting it from being accessed.

Using the instance called output, we access the method using:

output.displayname();

hello

HTML5 Canvas: More effect methods

This entry is part 8 of 17 in the series HTML5 Canvas

The following are some of the more common effect methods that are available for
shapes:

  • strokeStyle: Specifies the color or style for lines around shapes
  • fillStyle: Specifies the color or style used inside shapes
  • shadowOffsetX/shadowOffsetY: Specifies the distance of the shadow
  • shadowBlur: Specifies the level of the blurring effect
  • shadowColor: Specifies the color of the shadow
  • createLinearGradient: Creates a linear gradient inside the shape
  • createRadialGradient: Creates a radial gradient inside the shape
<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='utf-8'>
    <title>Codecrawl.com: Styling a square</title>
    <style>
        canvas {
            border: 1px solid #000;
        }
    </style>
</head>
<body>
<canvas id='canvas' width='200' height='200'></canvas>
<script>
    var canvas = document.getElementById('canvas').getContext('2d');
    canvas.shadowOffsetX = 10;
    canvas.shadowOffsetY = 10;
    canvas.shadowBlur = 10;
    canvas.shadowColor = 'rgba(200, 0, 200, .3)';
    canvas.fillStyle = 'rgba(200, 0, 200, 1)';
    canvas.strokeStyle = '#09c';
    canvas.lineWidth = 5;
    canvas.fillRect(0, 0, 100, 100);
    canvas.clearRect(25, 25, 50, 50);
    canvas.strokeRect(25, 25, 50, 50);
</script>
</body>
</html>

The inner square is created by strokeStyle, lineWidth and strokeRect.  Its color is #09c.
Effect Methods Output

PHP & OOP: Magic Methods

This entry is part 11 of 11 in the series PHP & OOP

We have used __construct and __destruct in an earlier example.  These are called magical methods in PHP.

PHP reserves all function names starting with __ as magical. It is recommended that we do not use function names with __ in PHP.

Other magical functions are:

__construct(),

__destruct(),

__call(),

__callStatic(),

__get(),__set(),

__isset(),

__unset(),

__sleep(),

__wakeup(),

__toString(),

__invoke(),

__set_state()

and __clone().

 

PHP & OOP: Methods of a class

This entry is part 7 of 11 in the series PHP & OOP

In object-oriented programming, the member functions of a class are also called methods of the class.

If you read any literature related to object-oriented programming, you will come across this word frequently.

Look at the following example:

<?php

class PopStar
{
    public $person;
    public $salary;
    public $album;

    public function setSalary()
    {
        $this->salary = 10000;
    }

    public function getSalary()
    {
        echo $this->salary;
    }
}

$star = new PopStar();
$star->setSalary();
echo "The pop star's salary is:";
echo "<br>";
$star->getSalary();

?>

There are 2 methods setSalary() and getSalary() in the above PopStar class.

From the code above, we can say that we are using the method setSalary() to set the salary of the pop star and method getSalary() to get the salary of the star.

jQuery: Common DOM manipulation methods

This entry is part 14 of 33 in the series jQuery Tutorial

We look at some of the more commonly used DOM manipulation methods such as .attr() and .appendTo().

MethodDescription
.appendTo()Insert every element in the set of matched elements to the end of the target.
.attr()Get the value of an attribute for the first element in the set of matched elements or set one or more attributes for every matched element.
.addClass()Adds the specified class(es) to each of the set of matched elements.
.after()Insert content, specified by the parameter, after each element in the set of matched elements.
.append()Insert every element in the set of matched elements to the end of the target.
.before()Insert content, specified by the parameter, before each element in the set of matched elements.
.clone()Create a deep copy of the set of matched elements.
.css()Get the value of a style property for the first element in the set of matched elements or set one or more CSS properties for every matched element.