oop

do you need the ref or out parameter?

I am passing a instance of a class to a method, and that method will modify the instance. Do I need to use the out or ref keyword since this is a class I am passing? This is what I want to do: public void Blah() { Blah b = Dao.GetBlah(23); SomeService.ModifyXml(b); // do I need to use out or ref here? Dao.SaveXml(b.xml);...

Is it a good idea to internally invoke the constructor in a static method?

Let's say for example I had a localised date class where the normal usage was to create an object. $d = new Date(mktime(), 'MM-DD-YYYY', array('locale' => 'es')); Now, what if I didn't want to always create a new object explicitly, but instead wanted something more along the lines of... <p>The date is <?php echo Date::formatDate( mk...

Is it possible to create or exchange Javascript properties on access

I would like to have some sort of lazy initialied object properties in javascript and would thus want to somehow overload the property read and write access i.e.: var someval = myobj.lazyprop; // invokes myobj.get("lazyprop"); myobj.lazyprop = someval; // invokes myobj.set("lazyprop",someval); where myobj is some object I provide ...

PHP Framework OOP model

Hello, I think I am experienced procedural PHP programmer. I've implemented a few bigger projects. Now I would like to try OOP PHP on lesser one (framework for DB import/export + user authentication). Since I've never tried OOP on such a project I have problem with object design. I would like to implement the framework the way, I'll ju...

Pointer to a class and function - problem

Firstly I'll show you few classes. class A { public: B * something; void callSomething(void) { something->call(); } }; class B { public: A * activeParent; B(A * parent) { activeParent = parent; } void call(void) { activeParent->something = new C; } }; class C : public B { publ...

PHP Design Pattern

Hi, I have a class that performs database operations and returns results (array, true, false). And I have an another class that creates JSON string by using this class in its constructor. Can we say this class is an Adapter? Or simply wrapper or ... Class Db { public function getRows($params) { //... } } Class DbAd...

How important are design patterns in web development?

What are the design patterns that I should be completely familiar with? And what is one easy example that each can be used for? I am a web developer (I use Django, and is familiar with separation of logic), but I work at a Desktop-app company. They are always talking about singletons, and I forget...but it leaves me no clue! ...

applying UML in PHP

most of the books that I have read on UML uses the Java language to show examples (one notable book is the ICONIX book from Apress entitle UML-Driven Object Modeling with ICONIX). The book follows several steps using UML diagrams and then implemented in JSP. Are there methodologies to "formally" implement UML diagrams in PHP? (something ...

How to refer to the calling class in Objective-C

Can you refer to the sender of a message without passing the sender as a parameter? This is simplified code for the sake of discussion: // mainTableViewController.m [dataModel loadData]; //Table is requesting data based on user input // dataModel.m -(void) loadData{ // I want to store the sender for later reference se...

What is the use of making constructor private in a class?

Why should we make the constructor private in class? As we always need the constructor to be public. ...

How to obtain feedback from an event?

I wonder how to obtain feedback from an event? Situation: Let's say that a object (Slave) can produce events(request changing a property). An other object (Master) subscribes to these events, analyzes the changing property value and accepts, or denies this change. Then the feedback is returned to the Slave, and it change or not its pro...

Moq and accessing called parameters

I've just started to implement unit tests (using xUnit and Moq) on an already established project of mine. The project extensively uses dependency injection via the unity container. I have two services A and B. Service A is the one being tested in this case. Service A calls B and gives it a delegate to an internal function. This 'callb...

Book about OO in practice

I am looking for a book which explains how to program object-oriented. I am not looking for a book which explains OO concepts: what classes and objects are, what private, protected and public do, what static and final means. I already know this. I would like for the book to explain how to program OO in practice, answering questions lik...

Object properties for an indeterminate number of levels

This question is similar to this one but (literally) takes it to another level, or levels. Background: I am using the Kohana PHP framework and, specifically, the ORM library. Basically, when you loop through DB results with it, you can access the field values as properties of an object. Any joined tables can be accessed in a hierarchic...

Diamond Problem

Wikipedia on the diamond problem: "... the diamond problem is an ambiguity that arises when two classes B and C inherit from A, and class D inherits from both B and C. If a method in D calls a method defined in A (and does not override the method), and B and C have overridden that method differently, then from which class does it inheri...

Unit testing CRUD operations when data source is configured in application server properties

Hi all! Please, tell me: How can I write unit test (e.g. with JUnit) for operation "insert into some table" when many properties for normal application work are saved in config files for application server? Thanks!a ...

naming convention for methods that return boolean or indicate binary state?

Can someone point me to a guide for naming methods that return boolean or indicate a boolean state? I'm talking about things I've named like recordsExist(), issetVariable(), questionPrompted(), commentAsked(). Thinking this over, I think that two basic problems I'm looking at are 1: Has a user-interface event happened? and 2: do[es] dat...

Coding myself into a corner

We've got a set of classes which derive from a common set of interfaces such that IFoo-> BasicFoo, ReverseFoo, ForwardFoo IBar -> UpBar, DownBar, SidewaysBar IYelp -> Yip, Yap, Yup wherein the constructor for the Foo's looks like Foo(IBar, IYelp) These items are used throughout the project. There exists another class which has a met...

Object Oriented Programming

I have confusion about the concept of inheritance in C++, suppose we have a class named computer and we publicly inherit a class named laptop from computer class. Now when we create an object of class laptop in main function what happens in the memory? Please Explain. ...

PHP OOP: Why a getter?

I'm a novice with OOP, and I'm having trouble grasping the necessity of a getter method. In the example: class foo { $this->bar = "test"; } $foo = new foo(); echo $foo->bar; What are the potential pitfalls in this situation, assuming I'm using a setter method to properly validate an updated value? ...