assalamualaikum. very good morning to all. :) 

 

today i would like to share about the if…else evolutions. 

 

in if..else evolution, many programmers often to use a basic if..then, if..else if, interface class, switch case, array, class, factoring & object-oriented class for a repeated things @ in a looping. we can see for every each differences at the example codes below:

 

1) if..then

eg:

if($marital_status = ‘single”)

{

echo “single”;

}

 

 

2)if..else if

eg:

if($marital_status = ‘single’ )

{

echo “single”;

}

else if 

{

echo “married”;

}

else

{

echo “widow”;

}

 

 

3) interface class 

eg:

if($marital_status == ‘single’)

{

echo “single”;

}

else if($marital_status == ‘married’)

{

echo “married”;

}

else

{

echo “unspecified”;

}

 

 

4)switch-case

eg:

switch($marital)

{

case ‘single’;

echo ‘single’;

case ‘married’;

echo ‘married’;

default

echo ‘unspecified’;

}

 

 

5)array

eg:

 $marital_status = array[];

{

‘single’ => ‘SINGLE’;

‘married’ => ‘MARRIED’;

}

 return marital_status_map[$marital_status];

 

 

6)class

eg:

class marital_status

{

  status=”unspecified”;

function print = status();

{

echo $this =>status();

class single extends maritalStatus

{

$status = ‘single’;

}

class married extends maritalStatus

{

$status = ‘married’;

}

 

 

7)factoring

eg:

class marital_status

{

status function factoring ($type)

{

return new $type();

}

}

$status = marital_status :: factory ($type);

 

 

8) object-oriented class

eg:

$status = new marital_status (new single)

 

 

all the above if..else evolutions from 1-7 are really waste our time. we always type the same code for a repeated time. only the no 8 loop, it is simple. only 1 by 1 added if needed. & the additional new objects will not effect other existing object. plus with OO, it is much faster than late, easy to maintain & not effect other if..else conditions. 

 

so, why dont we use object oriented class? lets try & apply it in your programs/systems/animation projects. remember, refactor your codes. we are a computer science’s students. make it simple & easy to maintain & understand by other programmers/developers. especially for a newbies @ beginners. 

 

 

wassalam.🙂

About fzfain88

islam. moderate. programmer. did all because allah. :)

One response »

  1. Reid Baccus says:

    Attractive section of content. I just stumbled upon your weblog and in accession capital to assert that I acquire in fact enjoyed account your blog posts. Any way I will be subscribing to your augment and even I achievement you access consistently rapidly.

As salam. Hi. Leave a Comment?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s