Saturday, February 16, 2008

Object Oriented Concepts - Difference between generalization and realization

Generalization connects a sub-class to a super-class. It’s another name for inheritance. Realization connects a class to an interface. It’s another name for implementation.

Generalization is equivalent to public inheritance in C++ or ‘extends’ in java. It implies inheritance of interface and implementation.

Realizes is equivalent to ‘implements’ in java. It represents conformance to an interface as opposed to inheriting anything.

Object Oriented Analysis Design OOAD Tips

Object Oriented Basics Concepts Fundamentals

Inheritance in Programming Languages

Object Oriented Programming Advantages Disadvantages

CMM software

Java Programming Interview Questions

  • Can you load server object dynamically? If so what are 3 major steps involved in it?
  • Can you run product development on all operating systems?
  • Considering notepad/IE or any other thing as process, What will happen if you start notepad or IE 3 times ? Where three processes are started or three threads are started?
  • Difference : AWT and Swing?
  • Difference : Abstract class and Interface?
  • Difference : Grid and Gridbaglayout?
  • Difference : Process and Thread?
  • Difference : java and c++?
  • Difference : process and threads?
  • Does java support function overloading, pointers, structures, unions or linked lists?
  • Does java support multiple inheritance? if not, what is solution?
  • Explain 2-tier and 3-tier architecture?
  • Explain about version control?
  • Have you ever used HashTable and Directory?
  • How can two threads be made to communicate with each other?
  • How can we do validation of fields in project?
  • How can you know about drivers and database information ?
  • How do you download stubs from Remote place?
  • How does thread synchronization occur in monitor?
  • How java can be connected to database?
  • How will you add panel to frame?
  • I want to store more than objects in remote server? Which methodology will follow?
  • In container there are 5 components. I want to display all component names, how will you do that?
  • In htm form I have button which makes us to open another page in seconds. How will you do that?
  • In htm page form I have one button which makes us to open new page in seconds. How will you do that?
  • Is there any tag in htm to upload and download files?
  • Meaning of Servelet? What are parameters of service method?
  • Meaning of Session? Explain something about HTTP Session Class?
  • Meaning of Static query and Dynamic query?
  • Meaning of class loader? How many types are there? When will we use them?
  • Meaning of cookies? Explain main features?
  • Meaning of distributed application? Why are we using that in our application?
  • Meaning of flickering?
  • Meaning of function overloading and function overriding?
  • Suppose if we have variable ‘I’ in run method, if I can create one or more thread each thread will occupy separate copy or same variable will be shared?
  • Tell some latest versions in JAVA related areas?
  • What are JVM.JRE, J2EE, JNI?
  • What are Normalization Rules? Define Normalization?
  • What are abstract classes?
  • What are adapter classes?
  • What are advantages of java over C++?
  • What are benefits if Swing over AWT?
  • What are byte codes?
  • What are files generated after using IDL to java compiler?
  • What are session variable in servlets?
  • What are statements in Java?
  • What are streams?
  • What are swing components?
  • What are traverses in binary tree?
  • What are virtual functions?
  • What do you know about garbage collector?
  • What do you mean by light weight and heavy weight components?
  • What do you mean by multithreading?
  • What is JAR file?
  • What is JFC?
  • What is JNI?
  • What is base class for all swing components?
  • What is client server computing?
  • What is constructor and virtual function? Can we call virtual function in constructor?
  • What is corresponding layout for card in swing?
  • What is difference abstract class and interface?
  • What is exact difference in between Unicast and Multicast object? Where will it be used?
  • What is functionability stubs and skeletons?
  • What is functionality of stub?
  • What is interface?
  • What is layout for toolbar?
  • What is light weight component?
  • What is main functionality of Prepared Statement?
  • What is main functionality of remote reference layer?
  • What is mapping mechanism used by java to identify IDL language?
  • What is middleware? What is functionality of web server?
  • What is polymorphism?
  • What is protocol used by server and client?
  • What is role of Web Server?
  • What is root class for all java classes?
  • What is serializable interface?
  • What is serialization?
  • What is thread?
  • What is update method called?
  • What is use of interface?
  • What is user defined exception?
  • When will you use interface and abstract class?
  • Where are card layouts used?
  • Why do we use oops concepts? What is its advantage?
  • Why do you canvas?
  • Why does java not support multiple inheritance?
  • Why is java not fully objective oriented?
  • Why is java not pure oops?
  • Why java is considered as platform independent?
  • Why there are some null interface in JAVA? What does it mean? Give some null interface in JAVA?
  • Write down how will you create Binary tree?
  • Write program for recursive traverse?
  • what is meant wrapper classes?
Source: http://www.sharpprogrammer.com/interview-questions/java-programming-interview-questions/

OOAD and UML Interview Questions

  1. Can method be overloaded based on different return type but same argument type?
  2. Describe some techniques for expressing business rules/constraints either in UML or via other means.
  3. Describe the use of UML stereotypes in one of your recent projects (you used stereotypes to express what?). Feel free to include small example.
  4. Describe useful application of an “extends” use case (in what situations would you use an “extends” use case instead of any of the other kind of use case relationships?)
  5. Differentiate Aggregation and containment?
  6. Differentiate between template class and class template.
  7. Differentiate between the message and method.
  8. Differentiate persistent & non-persistent objects?
  9. Differentiate the class representation of Booch, Rumbaugh and UML?
  10. Do you feel UML (or other types of) models have any value once the implementation code has been generated? Why?
  11. Explain the difference between composition and aggregation.
  12. Explain the difference between design model and an implementation model.
  13. Explain the different relationship notations in UML that you have used (e.g., generalization, association, and so on.)
  14. If familiar with it, describe how you used any one of the “gang of four” design patterns in recent model you produced.
  15. If familiar with it, describe the “design by contract” approach.
  16. If familiar with it, describe the concept of UML profile.
  17. In RUP business modeling, what is the difference between Business Actor and Business Worker?
  18. In the past, have you ever traced design and/or implementation artifacts back to the user requirements? If yes, how?
  19. Is object persistence expressed in the analysis model, the design model or both? Explain.
  20. Is there anything in RUP that you would change in order to improve the efficiency of the development process. Fit in an analysis or design model?
  21. List out some of the object-oriented methodologies
  22. Object Oriented: Essentials and History
  23. What do u meant by “SBI” of an object?
  24. What is dangling pointer?
  25. What is down casting?
  26. What is meant by “method-wars”?
  27. What is modifier?
  28. What is the difference between business use case and system use case?
  29. What is the difference between cohesion and coupling? Why are “strong cohesion” and “loose coupling” patterns generally recommended in OOAD?
  30. What is the format in which model can be saved inventor/tool neutral way?
  31. When does name clash occur?
  32. Whether unified method and unified modeling language are same or different?
  33. Which UML diagrams have you used? Explain when to use one or the other. Use Case Diagram, Class Diagram, Sequence Diagram, Activity Diagram
  34. Who were the three famous amigos and what was their contribution to the object community?
  35. Why generalization is very strong?
  36. Would you use sequence diagram or an activity diagram to model process flow that has lot of conditional flows and concurrent processing?
Source : http://www.sharpprogrammer.com/interview-questions/ooad-and-uml-interview-questions/

C Programming Interview Questions

  • Are expressions arr and *arr same for array of integers?
  • Are variables argc and argv are local to main?
  • Bitwise operator for checking whether particular bit is on or off?
  • Bitwise operator for putting on particular bit in number?
  • Bitwise operator for turning off particular bit in number?
  • Can Structure contain Pointer to itself?
  • Can there be at least some solution to determine number of arguments passed to variable argument list function?
  • Can we specify variable field width in scanf() format string? If possible how?
  • Can you dynamically allocate arrays in expanded memory?
  • Can you use function fprintf() to display output on screen?
  • Can you write function similar to printf()?
  • Describe about storage allocation and scope of global, extern, static, local and register variables?
  • Difference : Strings and Arrays?
  • Difference : Structure and Unions?
  • Difference : arrays and linked list?
  • Difference : enumeration and set of pre-processor # defines?
  • Difference : functions memmove() and memcpy()?
  • Difference : functions rand(), random(), srand() and randomize()?
  • Difference : main() in C and main() in C++?
  • Difference : pass by reference and pass by value?
  • Difference : strdup and strcpy?
  • Differentiate between for loop and while loop? it uses?
  • Does mentioning array name gives base address in all contexts?
  • Does there exist any other function that can be used to convert integer or float to string?
  • Does there exist any way to make command line arguments available to other functions without passing them as arguments to function?
  • Explain one method to process entire string as one unit?
  • How are Structure passing and returning implemented by complier?
  • How can called function determine number of arguments that have been passed to it?
  • How can we check whether contents of two structure variables are same or not?
  • How can we read/write Structures from/to data files?
  • How much maximum can you allocate in single call to malloc()?
  • How will you declare array of three function pointers where each function receives two ints and returns float?
  • If we want that any wildcard characters in command line arguments should be appropriately expanded, are we required to make any special provision? If yes, that?
  • In header file whether functions are declared or defined?
  • In header files whether functions are declared or defined?
  • Increase size of dynamically allocated array?
  • Increase size of statically allocated array?
  • Out of fgets() and gets() that function is safe to use and why?
  • Program : compare two strings without using strcmp() function.
  • Program : concatenate two strings.
  • Program : find Factorial of number.
  • Program : generate Fibonacci Series?
  • Program : interchange variables without using third one.
  • Program : s for String Reversal. same for Palindrome check.
  • Program : that employs Recursion?
  • Program : that uses command line arguments.
  • Program : that uses functions like strcmp(), strcpy(), etc.
  • To that numbering system can binary number be easily converted to?
  • Use bsearch() function to search name stored in array of pointers to string?
  • Use functions fseek(), freed(), fwrite() and ftell()?
  • Use functions memcpy(), memset(), memmove()?
  • Use functions randomize() and random()?
  • Use functions sin(), pow(), sqrt()?
  • Use qsort() function to sort array of structures?
  • Use qsort() function to sort name stored in array of pointers to string?
  • What advantages of using Unions?
  • What do functions atoi(), itoa() and gcvt() do?
  • What do ‘c’ and ‘v’ in argc and argv stand for?
  • What does error ‘Null Pointer Assignment’ mean and what causes this error?
  • What does static variable mean?
  • What is NULL Macro? Difference : NULL Pointer and NULL Macro?
  • What is NULL Pointer? Whether it is same as uninitialized pointer?
  • What is far pointer? where we use it?
  • What is linklist and why do we use it when we have arrays? - I feel correct answer should be linklist is used in cases where you don’t know memory required to store data structure and need to allocate is dynamically on demand.
  • What is maximum combined length of command line arguments including space between adjacent arguments?
  • What is near, far and huge pointers? How many bytes are occupied by them?
  • What is object file? How can you access object file?
  • What is pointer?
  • What is recursion?
  • What is similarity between Structure, Union and enumeration?
  • What is static identifier?
  • What is structure?
  • What is use of typedef?
  • When reallocating memory if any other pointers point into same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?
  • Where are auto variables stored?
  • Where does global, static, local, register variables, free memory and C Program instructions get stored?
  • Write down equivalent pointer expression for referring same element a[i][j][k][l]?
  • advantages of using pointers in program?
  • advantages of using typedef in program?
  • bit fields? What is use of bit fields in Structure declaration?
  • declare following: array of three pointers to chars, array of three char pointers, pointer to array of three chars, pointer to function that receives int pointer and returns float pointer, pointer to function that receives nothing and returns nothing
  • detect loop in linked list?
  • differences between malloc() and calloc()?
  • differences between structures and arrays?
  • different storage classes in C?
  • dynamically allocate one-dimensional and two-dimensional array of integers?
  • enumerations?
  • implement substr() function that extracts sub string from given string?
  • macros? advantages and disadvantages?
  • obtain current time and Difference : two times?
  • obtain segment and offset addresses from far address of memory location?
  • print string on printer?
  • register variables? advantage of using register variables?
  • that function should be used to free memory allocated by calloc()?
  • that header file should you include if you are to develop function that can accept variable number of arguments?
Source: http://www.sharpprogrammer.com/interview-questions/c-programming-interview-questions/

Data Structure Interview Questions

  • A list is ordered from smaller to largest when sort is called. Which sort would take longest time to execute?
  • A list is ordered from smaller to largest when sort is called. Which sort would take shortest time to execute?
  • Convert following infix _expression to post fix notation ((a+2)*(b+4)) -1 (Similar types can be asked)
  • Evaluate following prefix _expression ” ++ + - (Similar types can be asked)
  • Explain about types of linked lists
  • Explain binary searching, Fibinocci search.
  • Explain quick sort and merge sort algorithms and derive time-constraint relation for these.
  • How is it possible to insert different type of elements in stack?
  • How many different binary trees and binary search trees can be made from three nodes that contain key values 2 & 3?
  • How will inorder, preorder and postorder traversals print elements of tree?
  • How would you sort linked list?
  • In which data structure, elements can be added or removed at either end, but not in middle?
  • Parenthesis are never needed in prefix or postfix expressions. Why?
  • Stack can be described as pointer. Explain.
  • The element being searched for is not found in array of elements. What is average number of comparisons needed in sequential search to determine that element is not there, if elements are completely unordered?
  • What data structure would you mostly likely see in non recursive implementation of recursive algorithm?
  • What do you mean by Base case, Recursive case, Binding Time, Run-Time Stack and Tail Recursion?
  • What do you mean by: * Syntax Error * Logical Error * Runtime Error How can you correct these errors?
  • What does abstract data type means?
  • What is average number of comparisons in sequential search?
  • What is average number of comparisons needed in sequential search to determine position of element in array of elements, if elements are ordered from largest to smallest?
  • What is data structure?
  • What is maximum total number of nodes in tree that has N levels? Note that root is level (zero)
  • When will you sort array of pointers to list elements, rather than sorting elements themselves?
  • Which data structure is needed to convert infix notations to post fix notations?
  • Which one is faster? binary search of orderd set of elements in array or sequential search of elements.
  • Which sort show best average behavior?
  • Write Binary Search program
  • Write programs for Bubble Sort, Quick sort
  • Write programs for Linked List (Insertion and Deletion) operations
Source: http://www.sharpprogrammer.com/data-structures/data-structure-interview-questions/

A lot of Programming books

Go http://www.33367.com/
here tons of programming books. easy to download...................

Monday, February 11, 2008

Ajax.NET - A free library for the Microsoft .NET Framework

Ajax.NET - Download Details
Download the latest Ajax.dll (5.7.22.2) to use it for free in your web projects.
You can also download the Ajax.dll (5.7.25.1) Beta for the new Microsoft .NET Framework 2.0.
The source code of Ajax.NET is now available! More details...

UpdatePanel tutorial ASP.NET AJAX

What ist the UpdatePanel in ASP.NET Ajax? The answer is easy: When adding an UpdatePanel-control to your page, you can achieve a partial-update of your page on a postback. Only the content in the UpdatePanel is refreshed, the other parts of the page remain unchanged. This topic explains, how you can setup an Ajax-enabled project and use the UpdatePanel control.
More: http://www.codegod.de/WebAppCodeGod/updatepanel-tutorial-aspnet-ajax-AID281.aspx

A Chat with ASP.NET and Ajax

This article describes how to implement a web-chat with ASP.NET and Ajax. In the first part I introduce the technologies I used for the application. Then I explain the concept of a chat and in the last part I present the main implementations.The goal of this article is to show the interested reader how to develop a chat without browser-plugins or java-applets, just pure HTML and javascript.

CakePHP News

The CakePHP Development Site

Submitting Tickets
Before submitting a ticket read this: Bug Reporting. Make sure you have searched the CakePHP Google Group, and through the tickets that have already been submitted. Another suggestion is to grab the latest nightly or use the branch where many problems are fixed on a daily basis. You must be registered to submit tickets: Register here.

Latest Version

1.1

CakePHP 1.1.18.5850
1.1 Nightly Build
svn co

https://svn.cakephp.org/repo/trunk/cake/1.1.x.x /path/to/save
1.2
Whats in 1.2?
CakePHP 1.2.0.5875 pre-beta
1.2 Nightly Build
svn co

https://svn.cakephp.org/repo/trunk/cake/1.2.x.x /path/to/save

Documentation Efforts
We are still hard at work on the documenation. You can help by submitting Documentation tickets. The Documentation tickets could be bugs (if you find a typo or problem), enhancements (if you know a cool function and want to document it) or RFCs ( if you want something described better). Hopefully, this will help centralize the efforts in our ongoing attack to get all the features documented. Select the milestone/version for 1.x.x.x Manual and we will do our best to have updates quickly.
Getting Started with Cake
Download
CakePHP.org
The Bakery
CakePHP Manual
CakePHP Google Group
Visit us at #cakephp on irc.freenode.net
* Remember that when you submit something to this site, you are giving us permission to use, reproduce, and modify the contribution in any way, shape, or form.
addHeadingLinks(document.getElementById("searchable"), "Link to this section");

Sending emails

PHP offers the possibility to send email in a simple easy way, to that end the language provides us with the statement mail()
More details: http://www.webestilo.com/en/php/php10a.phtml

Method GET y POST

In the previous page we have indicated that data in a form is sent through the method indicated in the attribute METHOD of the tag FORM, the two possible methods are GET and POST.


The difference between these two methods is in the way of sending data to the page, while the GET method sends data using URL, the POST method sends them through the standard entrance STDIO

more details: http://www.webestilo.com/en/php/php09b.phtml

Thursday, February 7, 2008

CakePHP Links

CakePHP.org
The official website

The Manual
The Cake manual

The API
The entire Cake API document

The Google Group
Actively discussing Cake development

Blogs about Cake
RD11
gwoo's blog about Cake, written in Cake

Cake baker
Daniel Hofstetter's blog about using Cake

H3rald
Fabio Cevasco's site written in Cake

Ajax Professional Programmer

Where are you?
Ajax professional programmer?
I know where your are! ;-)
I think this a best and small ajax professional programmer choice: jquery.com
Small. Compact. Useful. Ajax.
But if you ajax professional programmer, may be you wanna to use prototype.org
More Object Oriented Library for real ajax professional programmer in ajax style.But as for me, not ajax (not so) professional programmer -
it's hard to understanding, and really better to use small and for dummies (like me) jQuery lib.Ok, resume: The Better Choice for Ajax Professional Programmer - jQuery. Yah Yah! ;-)))

Easy Way To Upload Files Up To Your Server

(You can find fresh version of this component at Code Snippet)
Just one moment! Do not use
$html->file ('UserFile');
Because construction
$_FILES['data[User][File]'] doesn't work (PHP 4.1.* at least).
So use standart html code:

Then
$this->filehandler->upload('userfile','dir');
Remember, You must creating directory at your webroot ;-)
With 777 access ;-) ..........................
Go:http://cake-php.blogspot.com/2006/09/easy-way-to-upload-files-up-to-your.html

How To Integrate WYSIWYG Editor into CakePHP?

Easy way to integrate Xihna into CakePHP.
Easy way to integrate TinyMCE into CakePHP.
And, of couse, it's SO EASY to integrate FCKEditor into CakePHP ;-)
But if you asked me about WYSIWYG Editor, I say to you: "I don't like WYSIWYG! And use MarkDown PHP.
So, about MarkDown "non-visual editor" next time. Ok? ;)

Need Different Title For Page? It's simple!

Just add this code in head your views:

pageTitle="Page title goes here"?>


But remember, in cakephp 1.2.xx you can achieve this by
$this->set(‘title’, ‘Foo bar’);
Of couse, you must setup this variable (pageTitle) in your controller ;-)

Navigation Helper The Best of!

If you want get code like this:


You can use useful ;) helper - Navigation Helper!
Code like this:
link('My account',"/users/account/",array('activeAction'=>'account'))?>
link('Browse',"/items/browse/",array('activeAction'=>'browse'))?>
link('Create Item',"/items/add/",array('activeAction'=>'add','activeController'=>'items'))?>
link('Create Item',"/users/add/",array('activeAction'=>'add','activeController'=>'users'))?>
So... When user travel into your site and change /items/add -> users/add - the different menu be displayed (class = "active" I mean).
Just add code like thisrender(null,array('id'=>'main_nav'))?>
In your views! ;-)
Easy Way? Yes! Easy!
You can find more detail information here. And download navigation helper (sorry it's not direct link, because this file present in other blog).

How To Make Controller Without a Model?

class MyController extends AppController{
// var $uses = null; works too
var $uses = array();
function index() {
}
}
If you omit the “var $uses = array();” you will get a “missing model” error.
Thank's to CakeBaker!

How To Make Model Without a Table? Easy Decision!

The answer is simple:
class ModelWithoutTable extends AppModel {
var $useTable = false;
}

How To Validate data Without Saving?

You know, CakePHP check data only when you saving:
$this -> User -> save ($this->data)
But if you do not needing to save data?
In this case, you can use this "hint":
if ( $this -> User -> validates ( $this -> data ) ) { // OK, good to go
}
else { $this->set( 'data', $this->params['data'] ); $this->validateErrors( $this->User ); $this->render();
}
This code snippet made by Devo.

21 Things You Must Know About CakePHP

Easily creating static pages
I needed to create several pages that didn't use any models and contained static data inside the default layout. My first thought was to create a controller for these pages and define an action for each static page I needed. However, this solution seemed tedious and would make it difficult to quickly add new pages. Enter the pages controller - simply create a view inside the views/pages/ folder and it'll automatically be rendered in /pages. For example, if I created /views/pages/matt.thtml it would be accessible via http://www.example.com/pages/matt

Static pages - Adjusting the page title
If you're using the pages controller and you need to change the page title, add the following to your view:
pageTitle = 'Title of your page.'; ?>

Static pages - Adjusting other data sent to the layout
If you need to send data to the layout (such as a variable indicating what section to highlight on the nav bar), add this to your view:
_viewVars['somedata'] = array('some','data'); ?>
That array should then be accessible as $somedata inside your layout.

Creating a simple admin center
If you need to create an administrative back-end for your CakePHP site and would like all the actions with administrative capabilities to exist under a specific folder, open up config/core.php and uncomment: define('CAKE_ADMIN', 'admin');This will then make all actions that are prefixed with "admin_" to be accessible via: /admin/yourcontroller/youraction. For instance, if I created an action in my posts controller called "admin_add," I would access this via: www.example.com/admin/posts/addFrom there I could simply password the admin folder to prohibit unwanted users from adding posts.

Viewing the SQL queries that are running behind the scenes
You can easily see the SQL queries that CakePHP is running by adjusting the DEBUG constant in config/core.php. 0 is production, 1 is development, 2 is full debug with SQL, and 3 is full debug with SQL and dump of the current object. I typically have debug set at 2, which renders a table at the bottom of the page that contains SQL debug information. If rendering a table at the bottom of your site is constantly breaking your layout during development (especially if you're making AJAX calls and you're getting SQL inside your pages, not just the bottom), you can easily style this table to be hidden by adding this to your CSS:
#cakeSqlLog { display: none; }
This will allow you to view debug information in the HTML source code without your layout getting mangled, just don't forget to set debug back to 0 when your site goes live.

Multiple sources of documentation
Don't just rely on the manual. The wiki and the API are invaluable sources of information. The tutorials in the wiki are especially useful, and the API may be daunting at first, but you'll quickly find the information in there is crucial to building a site with CakePHP.

Using bake.php
Bake is a command line PHP script that will automagically generate a model, controller, and views based on the design of your database. I highly recommend using scaffolding to get a prototype going of a table that may change a lot in the beginning. If you're fairly certain the data is not subject to any drastic change, I recommend using bake instead. With bake all the files are generated and written to disk and you can make modifications from there. It saves a lot of time doing the repetitive tasks such as creating associations, views, and the basic CRUD controller operations. Using bake is really easy. Once you have a table(s) in your database created, change directories to the /cake/scripts/ folder and run:
php bake.php
If you choose to bake interactively it'll walk you through the steps required to create your model, controller, and views. Once everything has been baked I usually go through all the generated code and make custom modifications as needed.

Mind permissions when moving cake around
When I changed from the development server to the live server I tarred up my entire cake directory and scp'd it to the new server. Immediately I started having an issue where any time the debug level was set to 0 (production mode), data would not be returned for certain database calls. This was a bit of a catch 22 since I needed to view debug information to troubleshoot the problem. Someone in #cakephp kindly pointed out that permissions on the /app/tmp folder need to be writeable by apache. I changed the permissions to 777 and the issue went away.

Complex model validation
I needed to validate beyond just checking to make sure a field wasn't empty or it matched a regular expression. In particular, I needed a way to verify that the email address users registered with was unique. In the wiki I found this gem: this advanced validation tutorial, which covers some advanced methods of validation that were very useful.

Logging errors
$this->log('Something broke');
This will log your error to /tmp/logs/ (I initially made the mistake of thinking it would log it to the apache error log)
Creating a controller that uses other models
Suppose you have a controller that needs data from a bunch of different models, simply add this to the top of your controller:
class yourController extends AppController {
var $uses = array('Post','User');
}
This controller would then have access to both the Post and the User model.

Creating a model for a table that doesn't actually exist in the database
I needed a way to create a model and controller without actually having an associated table in the database. I particularly wanted to make use of the $validate array so I could easily validate my fields and keep the validation logic in the model. CakePHP will throw an error if you create a model for a table that doesn't exist. Adding this to the model fixed the problem:
var $useTable = false;
You can use this to change tables names as well.
var $useTable = 'some_table';

Call exit() after redirecting
This should be no surprise to anyone who has done any serious web development in the past, but make sure you call exit() after running $this->redirect() if there's code afterward that you don't want to run. I've always done this in the past, but I made the assumption that $this->redirect() would make an exit call for me (which it didn't).

Advanced model functions
Unless you delve in to the API, there are some very useful model functions at your disposal you might not know exist. I highly recommend reading over the Model Class Reference at least once. Here's a few key functions I wasn't aware of that I found to be very useful:
generateList() - I use this function primarily to populate select boxes with data from associated tables
findBySql() - Sometimes you just need to write your own SQL
findCount() - Returns number of rows matching given SQL condition
hasAny() - Returns true if a record that meets the given conditions exists.
Again, I highly recommend reading over the entire model class reference, you'll be surprised at what you learn.

Inserting multiple rows in succession
I had a situation where I needed to iterate through a list of items and insert new rows for each. I quickly discovered that if you insert an item and then immediately insert another, the item that is inserted next doesn't insert at all. Instead the previously inserted row was being updated. For example:
$items = array('Item 1','Item 2','Item 3');
foreach ($items as $item) {
$this->Post->save(array('Post' => array('title' => $item)));
}
This code will result in a single entry in the posts table: "item 3." CakePHP inserted "item 1", but then updates it to become "item 2," then "item 3" because $this->Post->id gets the value of the last inserted ID. Normally this functionality is very useful, but in this particular instance it was not. I found was to setting $this->Post->id = false after each insert solved the problem.

Inserting logic before or after controller functions
Suppose you needed an array of colors to be available to every view rendered by your controller but you don't want to have to define this data in every action. Using the beforeRender() callback will allow you to do this:
function beforeRender() {
$this->set('colors',array('red','blue','green');
}
This would make $colors accessible in every view rendered by that controller. beforeRender() is called after the controller logic and just before a view is rendered. There's also beforeFilter() and afterFilter(), which are called before and after every controller action. For more information, read up on callbacks in the models section of the manual.

Adding a WYSIWYG editor to CakePHP
I found this great tutorial on getting TinyMCE set up with CakePHP. Basically you just link the tiny_mce .js file to your page and then add a small bit of init code to every page that you want textareas to be converted into TinyMCE editors.

Writing your own SQL for HABTM relationships
I had an issue with trying to create a HABTM (has-and-belongs-to-many) relationship where I needed to specify my own SQL statement. According to the docs (at the time of this writing) you should set finderSql in your model, but according to the cakePHP source you should set finderQuery instead. It's just a foul-up in the docs, but I figured it'd be worth noting to save others from having to figure it out for themselves. Trac ticket here: https://trac.cakephp.org/ticket/1217
Sending email
I found two tutorials in the wiki: Sending email and Sending email with PHPMailerI highly recommend the latter of the two, sending emails with PHPMailer is more secure and there's less of a headache because you don't have to deal with constructing the mail headers yourself.

Customizing HTML generated by the Helper
I needed to change the default "You can get a full list of available tags in /cake/config/tags.ini.php.
I wouldn't recommend modifying that file, however, because you could lose your changes when you upgrade CakePHP.

Creating a custom 404 error page
If you need to change the page that users see when a document is not found, create:/app/views/errors/error404.thtml

Source: Original >>

UML modeling simplifies software design

The Unified Modeling Language combines best practices, platform independence, and extensibility into a common language for modeling complex software solutions.
UML combines modelling methodologies

Rational Software’s Grady Booch, Ivar Jacobson, and Jim Rumbaugh created UML to combine various object-oriented modelling methodologies. One of their collaborative goals was to create a system for modeling that would provide meaningful information to the human designers while creating “executable artifacts” useful to the machine that would be processing the information. They collected input from a large pool of system architects and modeling tool manufacturers. The Object Management Group (OMG) released the UML standard in 1997.
Today, many large companies use UML for software development, including Hewlett-Packard, IBM, and Sun. In addition, many vendors utilise another OMG standard, Model Driven Architecture (MDA), to create tools that help translate UML designs into platform-specific architectures. Rational has a suite of products that actually generate code in a variety of programming languages based on UML input.
UML gives project managers, architects, and developers a common language for describing an intended solution. UML’s combination of common, spoken-language descriptions and symbolic representations of logical elements strikes the perfect balance between flexibility, extensibility, and usability.
A versatile standard
UML works in conjunction with project management methodologies and vendor tools and applications to help you define a solution’s architecture. UML is platform-independent by design; you can deploy it alone or with other OMG standards to develop object-oriented solutions based on best-practice modeling techniques. However, you can also use UML to design organisational architectures and other, non-software-related systems.
The UML specification that defines the OMG standard is available for free download. It describes the 12 diagram types, the elements used to create them, and semantics and notations used when modeling.
While you’re free to use any project management methodology in conjunction with UML, you may wish to evaluate tools that are available for your specific platform before committing to a technique. Some tools, such as Rational Rose, assume a specific methodology, such as the Rational Unified Process (RUP), and you may not get the full benefit if you stray too far. Many of the available tools offer functionality similar to Visio or other diagramming applications, with a splash of IDE thrown in for architectural verification and inclusion of existing code bases.
There are dozens of UML tools available, ranging in cost from free to several thousand dollars. The Objects by Design Web site has a long list of UML products to choose from. It’s a good place to start looking.
UML diagrams

The current version of UML, 1.4, contains nine diagram types and three model management elements that serve as the core of the UML system.
Each diagram consists of elements, represented by blocks, and relationships, represented by connectors. UML uses a vocabulary of standardised symbols to demonstrate various aspects of elements and relationships. These diagrams are broken down into the following categories:
Structural diagrams

  • Class diagram--An overview of the system. Lays out classes, the templates for model objects, including attributes and operations, and the relationships between classes. Shows how classes are related, but not explicitly what happens when the relationship is triggered.
  • Object diagram—Shows a particular instance of a class diagram, where specific details can offer more information. Often, aggregate, composite, or recursive relationships will become more apparent in an object diagram.
  • Component diagram—Outlines the physical structure of code components or modules and defines components in the system.
  • Deployment diagram—Shows the relationship between hardware and software, particularly at the component and server levels. Outlines which components are related and how.

Behaviour diagrams

  • Case diagram—Usually the result of use case studies. Contains use case, actor, communication, and other elements to demonstrate what the system does. This is often completed during or after requirements gathering.
  • Sequence diagram—Used to model real-time systems by demonstrating the sequence of messages passed from one element to another.
  • Activity diagram—Outlines an activity’s flow between affected objects. An activity is an action the system performs, such as those outlined in the case diagrams. Actions are highlighted, and connectors point to the next activity or activities in sequence. Very similar to a flowchart.
  • Collaboration diagram—Considered similar to the sequence diagram, except it emphasises the role that objects play. Uses sequence numbers to show order of events and outlines object relationships using messages as connectors.
  • Statechart diagram—Shows the various states that an object passes through as actions affect that object. The diagram has a starting point and at least one ending point. Blocks represent states, and connectors represent actions.


Model management elements

  • Packages—Signify a relationship between groups of UML classes. Each group of classes is given a package name and used in diagrams to summarise a logical relationship.
    Subsystems—Similar to a package, subsystems represent the relationships between components. They encapsulate the representation of the physical code into a manageable design element.
  • Models—Represent any UML diagram or description of a physical system. This element is usually used in metamodels or to represent a portion of a complex model.
    Together, these diagrams are used to build a comprehensive model of the system to be created and deployed.

UML builds on best practices

UML is popular for several reasons. First, it was created from best practices in object-oriented design as identified by hundreds of participants. Second, the focus on platform independence readily orients models toward portable and scalable applications. Third, when combined with the tools available for handling UML, the system is extended beyond mere development and remains useful throughout a product’s life cycle.
This overview of UML’s basic structures was intended to give you an understanding of how UML helps you model software architecture. If you’d like to see more in-depth information on UML, send an e-mail to ZDNet Australia's Builder Channel

Source:http://www.builderau.com.au/strategy/projectmanagement/soa/UML-modeling-simplifies-software-design/0,339028292,320267919,00.htm

Wednesday, February 6, 2008

MySQL 5.1 partitions in practice

MySQL 5.1 partitions in practice (MySQL DevZone)
This article explains how to test the performance of a large database with MySQL 5.1, showing the advantages of using partitions. The test database uses data published by the US Bureau of Transportation Statistics. Currently, the data consists of ~ 113 million records (7.5 GB data + 5.2 GB index).

Using XML in MySQL 5.1 and 6.0

Using XML in MySQL 5.1 and 6.0 (MySQL DevZone)
In this article, we discuss the XML functionality available in MySQL, with an emphasis on new features coming online in MySQL 5.1 and MySQL 6.0. We assume that you already have a working knowledge of XML, and that you know what the terms “valid” and “well-formed” mean. We also assume that you have some knowledge of XPath.

Load and Search MySQL Data Using VB.NET 2005 in Windows Applications

Load and Search MySQL Data Using VB.NET 2005 in Windows Applications (MySQL DevZone)
MySQL data load and search are very important business requirements in any Windows or Internet web application development. In general, any application needs to show a result set of data and/or a single record to the end-users. In Windows applications it is very popular to show a result set of data by using the DataGridView, ListView or TreeView controls. A single record can be shown by the simple combination of the following controls: TextBox, ComboBox, ListBox, CheckBox, RadioButton, etc. MySQL data search is provided by using the required ADO.NET data objects and by refreshing the controls if necessary. These two processes, data load and search, should be fast and should be done with the proper code which depends on the controls in the Windows Form or Web Page. In this article I will show you how load and sort MySQL data using the DataGridView control. To search MySQL data the LIKE SQL operator will be used. Both programming implementations are done by using stored procedures for MySQL 5.0 database engine.

MySQL Failover Strategy using State Management

MySQL Failover Strategy using State Management, introducing MPP - Part 1
Having a strategy for failover has become almost standard in the business world. Whether it is a total site failover from a NOC in one city to another, or just a simple redundant server. Over the years many technology solutions have been created for or adopted to MySQL to provide this type of strategy.
MySQL Failover Strategy using State Management, introducing MPP - Part 2
Now it's time to apply that concept to a load-balancer. In this Part 2 we will look at a strategy for using Linux Virtual Server with MPP for failover, and also take a closer look at the mechanics of MPP itself.
MySQL Failover Strategy using State Management, introducing MPP - Part 3
In this part 3 we will discuss how to configure and operate MPP, and additionally use MPP with MySQL Proxy to create a failover strategy.

Getting started with MySQL Proxy

Getting started with MySQL Proxy (MySQL DevZone)
The launch of MySQL Proxy has caused quite a commotion in the community. And with reason. For feature hungry people, this is undeniably the most exciting addition to MySQL set of tools.If the last statement has left you baffled, because you don't see the added value, don't worry. This article aims at giving you the feeling of what the Proxy can do.

Improving Database Performance with Partitioning

Improving Database Performance with Partitioning (MySQL DevZone)
A few years ago, I wrote an article entitled "The Foundation of Excellent Performance" (still available at http://www.tdan.com/i016fe03.htm) where I argued against the notion that SQL code was the number one contributor to performance in a database-driven system. Instead, I stated in the article that I firmly believed how good physical database design was far and away the leading component of superior database performance. In addition, I showed that Oracle's own research illustrated how poor design was the main culprit behind database downtime (planned or unplanned). In the years since then, I've not changed my stance and still think that any DBA who wants a high-performance database has got to invest in intelligent and savvy physical design to produce the kind of response times that make end users smile instead of scream.

Accessing Distributed Data with the Federated Storage Engine (MySQL)

Accessing Distributed Data with the Federated Storage Engine (MySQL DevZone)
It's no secret that corporations are swimming in more data than ever before. IDC has recently pegged data growth at 48% a year, which means that corporate data nearly doubles every two years at many companies. In addition, purchased applications and custom built systems continue to bring in new databases that require attention, and business intelligence remains a red-hot area for modern enterprises with many companies building analytic data warehouses or data marts that continually feed information to key decision makers

Managing Hierarchical Data in MySQL

Managing Hierarchical Data in MySQL (MySQL DevZone)
Most users at one time or another have dealt with hierarchical data in a SQL database and no doubt learned that the management of hierarchical data is not what a relational database is intended for. The tables of a relational database are not hierarchical (like XML), but are simply a flat list. Hierarchical data has a parent-child relationship that is not naturally represented in a relational database table

Javascript DataGrid using MVC pattern

Javascript DataGrid using the MVC pattern (CodeProject)
This grid supports resizing, draging, and sorting the columns. It was implemented using the MVC pattern.
Download demo project - 19.6 KB

Introduction

The MVC pattern is the way of breaking an application or GUI control into three parts: the controller, the model, and the view. The MVC pattern was designed to deal with input, data processing, and rendering the data into the GUI realm. The user input, data processing and rendering the data are separated and handled by the view, model, and controller objects.

Grid features

This grid supports dragging columns, resizing columns, and sorting columns. The double click on the column header will cause sorting the grid by the clicked header column. In order to resize columns, you need to move the header separator, holding the mouse button. It will cause junking the text labels in resizing column if they are too long to be in the cell. To drag a column you need to move the mouse on the header, holding the mouse button.The grid also has two kind of menus: the selected row menu and the grid menu. Right-clicking on row will cause an appearance of the selected row menu and right-clicking anywhere out of rows will cause an appearance of the grid menu.

The grid has two events "onRowUpdated" and "onRowAdded". These events fire on "Add","Update" button click and return the obj that contains new values for grid row.

Dynamic Table Filtering/Searching

Dynamic Table Filtering/Searching using DHTML and JavaScript (CodeProject)Easily add table filtering/searching capability to your webpage without requiring a round trip to the server.Download source - 3.2 KbWeb Development » Client side scripting

Beautify Javascript - Javascript Online Beautifier

Javascript Online Beautifierhttp://elfz.laacz.lv/beautify/ Online beautifier for javascript (js beautify, pretty-print)source:http://elfz.laacz.lv/beautify/beautify.php