Skip to content

Commit 76d9ba4

Browse files
committed
Code to practise factory method is complete.
1 parent 671cf68 commit 76d9ba4

File tree

13 files changed

+371
-1
lines changed

13 files changed

+371
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@
3636
.Trashes
3737
Icon?
3838
ehthumbs.db
39-
Thumbs.db
39+
Thumbs.db
40+
/nbproject/private/
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
//Client.php
3+
include_once('GraphicFactory.php');
4+
include_once('TextFactory.php');
5+
6+
class Client {
7+
8+
private $someGraphicObject;
9+
10+
private $someTextObject;
11+
12+
public function __construct() {
13+
$this->someGraphicObject=new GraphicFactory();
14+
echo $this->someGraphicObject->startFactory() . "<br />";
15+
$this->someTextObject=new TextFactory();
16+
echo $this->someTextObject->startFactory() . "<br />";
17+
}
18+
19+
}
20+
$worker=new Client();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
//Creator.php
3+
abstract class Creator {
4+
5+
protected abstract function factoryMethod();
6+
7+
public function startFactory() {
8+
$mfg= $this->factoryMethod();
9+
return $mfg;
10+
}
11+
12+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* To change this license header, choose License Headers in Project Properties.
5+
* To change this template file, choose Tools | Templates
6+
* and open the template in the editor.
7+
*/
8+
9+
//GraphicFactory.php
10+
include_once('Creator.php');
11+
include_once('GraphicProduct.php');
12+
class GraphicFactory extends Creator {
13+
14+
protected function factoryMethod() {
15+
$product=new GraphicProduct();
16+
return($product->getProperties());
17+
}
18+
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
//GraphicProduct.php
3+
include_once('Product.php');
4+
class GraphicProduct implements Product {
5+
6+
private $mfgProduct;
7+
public function getProperties() {
8+
$this->mfgProduct="This is a graphic.<3";
9+
return $this->mfgProduct;
10+
}
11+
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
//TextProduct.php
3+
include_once('Product.php');
4+
class TextProduct implements Product {
5+
6+
private $mfgProduct;
7+
public function getProperties()
8+
{
9+
$this->mfgProduct="This is text.";
10+
return $this->mfgProduct;
11+
}
12+
13+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* To change this license header, choose License Headers in Project Properties.
5+
* To change this template file, choose Tools | Templates
6+
* and open the template in the editor.
7+
*/
8+
9+
include_once('Creator.php');
10+
include_once('TextProduct.php');
11+
12+
class TextFactory extends Creator {
13+
14+
protected function factoryMethod() {
15+
$product=new TextProduct();
16+
return($product->getProperties());
17+
}
18+
19+
}
20+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* To change this license header, choose License Headers in Project Properties.
5+
* To change this template file, choose Tools | Templates
6+
* and open the template in the editor.
7+
*/
8+
9+
include_once('Creator.php');
10+
include_once('TextProduct.php');
11+
12+
class TextFactory extends Creator {
13+
14+
protected function factoryMethod() {
15+
$product=new TextProduct();
16+
return($product->getProperties());
17+
}
18+
19+
}
20+

Test.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* How do you declare a function or method that you want to be accessed without instantiate the class?
4+
* - By defining function static
5+
*/
6+
7+
8+
Class AccessSpecifiers {
9+
10+
public static function testStatic() {
11+
return false;
12+
}
13+
}
14+
15+
/**
16+
* How do you create a child class of BaseClass ?
17+
* - Through inheritence using keyword extends
18+
*/
19+
Class MyParent {}
20+
21+
Class Son extends MyParent {}
22+
23+
/**
24+
* Please write a conditional block of code that
25+
* check if the variable $var exists, is not null
26+
* and it's a number.
27+
*/
28+
Class TestVar {
29+
30+
public static $var;
31+
32+
public static function checkVar($var) {
33+
self::$var = $var;
34+
if (property_exists(__CLASS__,'var') &&
35+
!is_null(self::$var) &&
36+
is_int(self::$var)) {
37+
echo self::$var;
38+
} else {
39+
echo 'undefined var';
40+
}
41+
}
42+
}
43+
//TestVar::checkVar(10);
44+
45+
/**
46+
* Write a function that adds a line to a log file
47+
* the current date and time with this format:
48+
* "[2013-09-23 00:30:15] - Status OK"
49+
*/
50+
Class LogString {
51+
52+
private $__var;
53+
54+
public function __construct() {
55+
error_log("[".date("Y-m-d H:i:s")."] - Status OK", 3, "error.log");
56+
}
57+
}
58+
59+
$obj = new LogString();
60+
61+
/**
62+
* Which is the default path where you set up the
63+
* configuration for the database?
64+
* /project/app/Config/database.php
65+
*/
66+
67+
/**
68+
* How you can get the value of a session variable
69+
* with key "foo" using CakePHP ?
70+
* $this->Session->read('foo');
71+
*/
72+

Test.txt

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
Object Oriented Programming (OOP)
2+
Git 8
3+
PHP 5 9
4+
CakePHP framework 9
5+
MySQL 9
6+
Javascript 8
7+
jQuery 9
8+
HTML 9
9+
CSS 8
10+
Linux/Unix based OS 8
11+
12+
Questions:
13+
14+
About OOP:
15+
How do you declare a function or method that you want to be accessed without instantiate the class?
16+
- By defining function static
17+
18+
Class AccessSpecifiers {
19+
20+
public static function testStatic() {
21+
return false;
22+
}
23+
}
24+
25+
How do you create a child class of BaseClass ?
26+
- Through inheritence using keyword extends
27+
Class MyParent {}
28+
29+
Class Son extends MyParent {}
30+
31+
About GIT:
32+
33+
If you accidentally add the wrong files to be commited using git add, how do you unstage them?
34+
- git rm --cached <file>
35+
36+
If you want to switch to another branch, what command you need to execute?
37+
- git checkout branchName
38+
39+
About PHP 5:
40+
41+
Please write a conditional block of code that check if the variable $var exists, is not null and it's a number.
42+
- Solution:
43+
Class TestVar {
44+
45+
public static $var;
46+
47+
public static function checkVar($var) {
48+
self::$var = $var;
49+
if (property_exists(__CLASS__,'var') &&
50+
!is_null(self::$var) &&
51+
is_int(self::$var)) {
52+
echo self::$var;
53+
} else {
54+
echo 'undefined var';
55+
}
56+
}
57+
}
58+
TestVar::checkVar(10);
59+
60+
Write a function that adds a line to a log file the current date and time with this format: "[2013-09-23 00:30:15] - Status OK"
61+
- Solution :
62+
Class LogString {
63+
64+
private $__var;
65+
66+
public function __construct() {
67+
error_log("[".date("Y-m-d H:i:s")."] - Status OK", 3, "error.log");
68+
}
69+
}
70+
71+
$obj = new LogString();
72+
73+
74+
About CakePHP
75+
76+
Which is the default path where you set up the configuration for the database?
77+
- /project/app/Config/database.php
78+
How you can get the value of a session variable with key "foo" using CakePHP ?
79+
- $this->Session->read('foo'); [$this is the reference to Controller child]
80+
81+
About MySQL
82+
83+
Write a single query to retrieve the information from 2 tables that are related( users and users_data) where the primary key on users is ID and the foreign key on users_data is USER_ID.
84+
- Query:
85+
SELECT users.*, users_data.* FROM users
86+
LEFT JOIN users_data
87+
ON users_data.USER_ID = user.ID;
88+
89+
Write a single query to retrieve all the queries that are currently running on the server .
90+
- Query
91+
SHOW PROCESSLIST;
92+
93+
About Javascript
94+
95+
How do access to the alt attribute of the following image element using javascript?
96+
- Using getElementsByTagName('img')[0].alt;
97+
Example :
98+
var testStr = '<img alt="ALT TEXT" src="myPic.jpg">';
99+
var tmp = document.createElement('div');
100+
tmp.innerHTML = testStr;
101+
var alt = tmp.getElementsByTagName('img')[0].alt;
102+
103+
104+
What is the protocol name behind ajax?
105+
- JSON
106+
107+
About jQuery
108+
109+
Write a piece of javascript code using jQuery that make the element with id "someElement" to appear on the screen using a fade in effect after the DOM is loaded.
110+
- Solution :
111+
$(document).ready(function () {
112+
$("#someElement"). fadeTo( "slow", 0.12 );
113+
});
114+
115+
How do you remove an element from the DOM using jQuery?
116+
- .remove([selector])
117+
118+
About HTML
119+
120+
Which is the doctype syntax for HTML5?
121+
<!DOCTYPE>
122+
123+
Which is the attribute and value required on forms to allow file uploads?
124+
- The type="file" attribute of the <input> tag with value "file"
125+
126+
About CSS
127+
128+
Which is the css property and its value to force to hide the scroll on any DOM element with fixed height when its content exceed its own height?
129+
- overflow=hidden
130+
131+
If you have to div elements next to each other with the property float:left, which CSS property do you need to add to the next element in order to get both of them to fill the same height on page and make the next one not a floating one?
132+
- Example:
133+
<style>
134+
body
135+
{
136+
margin:0;
137+
padding:0;
138+
}
139+
.container
140+
{
141+
position:relative;
142+
width:100%;
143+
}
144+
.right
145+
{
146+
float:left;
147+
width:150px;
148+
background-color:#b0e0e6;
149+
}
150+
</style>
151+
<div class="container">
152+
<div class="right">
153+
<p><b>Note: </b>When aligning using the position property, always include the !DOCTYPE declaration! If missing, it can produce strange results in IE browsers.</p>
154+
</div>
155+
<div style="position:relative; width:300px;">
156+
<p><b>Note: </b>When aligning using the position property, always include the !DOCTYPE declaration! If missing, it can produce strange results in IE browsers.</p>
157+
</div>
158+
</div>
159+
160+
About Linux / Unix based OS
161+
162+
Which protocol(s) you could use to connect to a server SHELL remotely?
163+
SSH
164+
Write a command to look for the word "logString" on all files with .ctp extension in the same director
165+
grep -rw "ads" /home/anit/*.ctp

0 commit comments

Comments
 (0)