MVC example in PHP

MVC is a design pattern that suggests to divide the system into three prats: The Model, The View and the Controller.
The Model represents the business data, logic and rules.
The View is the presentation of the Model data.
The Controller is the part that receives the user request and connects the Model with its corresponding View.
Now let’s consider the following example:
we have employees stored in the table EMPLOYEE

Read More…

Reusable solution for adding items as objects to a ComboBox in C#

When we add items to a .net component, we usually need each item to be a (key-value) pair that matches an id-value in our business data model.
A .net ComboBox accepts adding an item as an “Object” and calling its toString() to place the item text and we can retrieve this object by the method SelectedItem.
I will create a class that represents a key-value pair, the objects created from this class will be added to the combobox:
EyComboBoxItem.cs

using System;

namespace EyReusableSystem
{
    public class EyComboBoxItem
    {
        private string key;
        public string Key
        {
            set
            {
                this.key = value;
            }
            get
            {
                return this.key;
            }
        }
        private string val;
        public string Val
        {
            set
            {
                this.val = value;
            }
            get
            {
                return this.val;
            }
        }
        public EyComboBoxItem(string key, string val)
        {
            this.key = key;
            this.val = val;
        }

        public override string ToString()
        {
            return this.val;
        }
    }
}

Read More…

Applying the Producer-Consumer model to process action events in java

In the producer consumer model, we have two processes: the process A contains the producer object: an object producing data or services. In the process B, we have the consumer object: an object that consumes the produced data or services.
The problem happens when the production in process A goes faster than the consumption in process B. And vice versa,
the consumption in process B goes faster than the production in process A.

Producer-Consumer problem

Producer-Consumer problem

Read More…

Processing an xml file in Java built-in parsers

While HTML is basically used to display data by representing it through a set of predefined tags , the mainly purpose of XML (EXtensible Markup Language) is to store the data into a portable form using our own defined tags. The portability of XML enables incompatible systems to share its data easily through a tag-based structured document.
In Java JDK, there’re two built-in XML parsers:

DOM (Document Object Model)

SAX (Simple API for XML)

I will be writing a java program to parse an xml document of a simple phonebook using these two parsers.

Read More…

building a modern web button using CSS3

CSS3 has the ability to add a significant beauty to the webpage elements like the border radius, 3D shadow effects, background gradient and more. CSS3 can bring a big difference to the look and feel of our design and it’s now supported by most of the modern browsers.
Buttons are found in the forms generally, but we can also style our links to appear like buttons as they are clickable elements too.

Read More…

A Singleton pattern implementation in php

Singleton is a design pattern used to guarantee one instance of the class during the lifetime of the program. It also provides a global access point to the class. Singleton is usually used when we have to access some resource (a database ,a file, a memory…) and we must have the control over the creation of the object that will access it in order to keep our resource safe. The control can be efficient by forcing one and only one instance of our class to exist, letting all the other objects use this instance to access our resource.

Read More…