oop

Linq-to-Sql vs CRUD object?

I have a linq-to-sql object from a table. I want to store a similar data in the profile collection. Technically, I don't need all of the data in the linq2sql table and do not really prefer the legacy naming construct. My first thought would be to create a collection of CRUD objects. But, if I choose this solution I will have double the ...

Javascript inheritance idea??

EDIT: I posted before I thought everything out. Here is a better implementation of what was in my mind: http://stackoverflow.com/questions/3376188/javascript-inheritance-idea-part-2 Okay, so I've seen that the following is bad function A() { this.variable = 7; this.method = function() { alert(this.variable); }; } alpha = new ...

Is there a good way to avoid unused method parameter in some of the subclasses while applying strategy pattern?

I have the following scenario where I have different kinds of sales algorithms to calculate the sales price. FixedSaleStrategy does not need basePrice parameter while all the other strategy implementations need it. Is there a good way to avoid this redundant parameter? public abstract class SalesStrategy { public abstract double Get...

What is the difference this oop patterns pros and cons?

i writed some codes about oop pattern. But i cannot see clearly these two kind of usage advantage disadvantagages: Firs one: class Program { static void Main(string[] args) { Report rp = new Report(); rp.MakeReport(); rp = new ExcelReport(); rp.MakeReport(); ...

Functions outside the class

I just want to tell you that I am newbie to OOP and it is quite hard to me, but here is my code: class functions { function safe_query($string) { $string = mysql_escape_string(htmlspecialchars($string)); return $string; } } class info { public $text; function infos($value) { echo func...

PHP OOP working with a hierarchy of objects

Hi everyone, I have a Site object but I can't figure out how best to store a collection of Page objects on Site. The pages are hierarchical (a tree structure for a website navigation). I thought about a tree-like array of pages but that would be a pain to interact with - e.g. $site->pages[0][3][1]->addContent('<h1>lol</h1>'). I could us...

Custom Sorting in .NET

I have designed a Class for Parent Child relationship class Category { public string CatName; public string CatId; public IList<Category> childCategory = new List<Category>(); public void addChildCat(Category childCat) { this.childCategory.Add(childCat); } public Category SortedCategory(Category ...

static method vs static data

why cant we use non static data members declared outside a static method within a static method? ...

Declaring protected variables in methods

I've had a good look round and can't seem to find an answer to this problem. Basically I'm using the _call method to dynmically generate get and set methods, however when declaring a variable PHP's default is public. Is there anyway to declare a variable from within a class as protected? function __call($method, $arguments) { $pref...

Getting error: Cannot use object of type mysqli_result as array

I'm following a php pagination tutorial that uses MYSQL but I use MYSQLI object oriented all around my site. This is causing some errors.. For this part.. $sql = "SELECT COUNT(*) as num FROM categories"; $total_pages = $connection->query($sql) or die(mysqli_error($connection)); $total_pages = $total_pages['num']; I get *Fatal error:...

Duck Typing in Javascript

Could someone give me an example of Duck Typing inheritance in Javascript? I'm exploring OO javascript and I've heard about duck typing but can't see any examples of it being used in javascript. ...

How to change an attribute of a public variable from outside the class

Sorry about the title, I don't think I could explain it right: This is a simplified example class, this is working ok. (I also have a Save() method) public class busItem { public Item vItem; public busItem(int pItem_Id) { DBDataContext db = new DBDataContext(); Item vItemQue...

Somehow, my class doesn't manage to define some variables...

So, I'm using whatever Object-Oriented options has to try and make a neat static image class so all I have to do is add said class to Canvas, and it will draw itself out! To test if everything worked, I added up some alerts. Now my Function starts spewing 'undefined' at the third alert. function StaticImage(imgsource, cancontext, ex, wy...

Is it proper to use a default constructor with polymorphism?

I basically have something like this: class CGlToolBase { public: CGlToolBase(void) { } virtual void OnMouseDown(CGlEngine &glEngine, WPARAM wParam, LPARAM lParam); virtual void OnMouseMove(CGlEngine &glEngine, WPARAM wParam, LPARAM lParam); virtual void OnMouseUp(CGlEngine &glEngine, WPARAM wParam, LPARAM lPara...

class object in class with php oop

I am not even sure how to ask. I do this all the time in C# but for the life of me I cannot find any decent examples in PHP. Can you help? What I am trying to do is for example. Say I have a class called Company who has many Employees. I want to be able to store all the employees in the company class then later when I iterate throug...

How to handle database logic from model

Hi, I created a enterprise system model from a class diagram and converted it php object oriented code. What I have now is just an empty model, it's able to relate and the connections are handled. Now the next step is ahead. I have a database and have to put the object into the database. Now there is a lack of experience on my side. I...

How to get the class that created the current object?

I would like to prevent foo() from being executed by any other class than B. How can I check which class created object A? <?php class A { public function foo() { if (.... B ) // what should be on the dotts? echo 'I\'m created by class B, which is fine'; else echo 'Execution of foo() is n...

is it good to declare a function in views ?

i got situation where i have to work on legacy code. One thing, i have to do to have quick result is to define a function in views. Is it good ? how to avoid them ? ...

How We Achieve isolation class under test ?

i'm start to learn unit testing. i wonder what is the best way to isolate class under test ? ...

Foreach loop which results in object instantiation....

Hi, I have a requirement to accept an array of checked items from a table and update a field based on which items have been selected. Initially my thoughts where to simply loop over each of these items in the array and access a function in the specific class to update the status. I'm slightly concerned about this approach as it would m...