oop

Pattern for Wrapping Shell Commands in a Class

Despite its inadvisability, using PHP's shell commands to interact with non-php system commands remains a common way of quickly achieving certain results in web applications. Has anyone abstracted out the common use cases into a class library (something in Zend maybe?) that offers a more sane/common way of handling this? Every time I en...

Is it good convention for a class to perform functions on itself?

I've always been taught that if you are doing something to an object, that should be an external thing, so one would Save(Class) rather than having the object save itself: Class.Save(). I've noticed that in the .Net libraries, it is common to have a class modify itself as with String.Format() or sort itself as with List.Sort(). My qu...

How is Ruby fully Object Oriented?

So, I'm curious as to how Ruby is a fully object oriented language. I stumble over one problem that isn't really clear to me. If I define a function as follows def foo(text) print text end and I define the function outside of a class, how is this function an object? I realize that I can call foo.class And I get NilClass. Does t...

Why do we need to have Object class as baseclass for all the classes?

Either in C# or Java or in any other language which follows oops concepts generally has 'Object' as super class for it by default. Why do we need to have Object as base class for all the classes we create? When multiple inheritance is not possible in a language such as C# or Java how can we derive our class from another class when it i...

Structure/object hierarchy of a rich text editor in OO style

I'm developing a text comparator that supports rich text editing. Could anyone suggest me how the structure or object hierarchy of a rich text editor build with Java or other OO languages looks like? ...

Deep Object Graphs Hibernate

Our domain model is very tightly coupled and some classes that are mapped with hibernate are 6 collections deep. Currently we don't use lazy loading for these since the business layer passes some of the higher level classes around and retrieves some of their lower level children at which time the session will have been closed. Retrieving...

Learning resources for Object Orientated Programming

I am looking for a really good learning resource for OOP if anyone can tell me please? I have found several on JAVA but I am not learning Java, I just want the fundamentals of OOP so that it gives me a good base to work from for any other language. Any recommendations? Thanks! ...

Naming conventions for persistence layer: DAO vs Manager vs ... ?

DISCLAIMER: I'm almost sure that I've seen the same question before but I can't find it now. If someone finds that question, please, give a link. I heard at least two opinions on the best name for classes which implements CRUD operations: someone says that DAO is a classical name and everyone knows what it means, but others say that Man...

Is this use of isinstance pythonic/"good"?

A side effect of this question is that I was lead to this post, which states: Whenever isinstance is used, control flow forks; one type of object goes down one code path, and other types of object go down the other --- even if they implement the same interface! and suggests that this is a bad thing. However, I've used code like th...

Theory behind object oriented programming

Alonzo Church's lambda calculus is the mathematical theory behind functional languages. Has object oriented programming some formal theory ? ...

Codeigniter: when to use a model vs library?

I've starting using Codeigniter for a project recently (few months ago) but its getting a little out of hand with a bunch of models that need to interact with each other and I was wondering if I should be creating a library instead? In my case, I have a user action that happens when you win a game and it would get logged in my user_mod...

Error processing : return value vs exception in C++

In the course of asking about catching 'divide by 0' exception, I found that with C++, we can't do that. I mean, divide by 0 doesn't throw an std::exception. Some of the hints that I found were I have to check the value, and throw the exception by self. I say it's confusing, as I've thought that C++ adopted the exception idea in order...

Create User and Edit User - DRY or separation, which is more important

I'm wondering what more experienced developers think about how to handle almost identical processes, such as a user creating a profile and a user editing their profile. At the moment I have a single controller method and single view which handle the distinction between a new user and existing/editing user, just by passing around an $edit...

oop design: returning a boolean property rather than explicitly returning TRUE or FALSE

I have noticed that most PHP-based libraries or frameworks have classes that don't explicitly return the keywords TRUE and FALSE, instead: if(condition) { $this->boolean_property = FALSE; return $this->boolean_property } does this mean anything or is it just another "purist" move which does not present any advantage over the other...

Use of Constructors - Odd Doubt

I'm reading about constructors, When an object is instantiated for a class, c'tors (if explicitly written or a default one) are the starting points for execution. My doubts are is a c'tor more like the main() in C Yes i understand the point that you can set all the default values using c'tor. I can also emulate the behavior by writ...

Using this-> syntax in PHP to access non-static properties

I am new to PHP and am trying to write a very simple class: <?php class Course { private $credits; public function getCredits() { return $this->credits; } } ?> the problem is when I load this in a browser, I see: credits; } } ?> so it looks like the browser is echoing all that follows "thi...

OO database class

Hi everyone. I'm trying to learn object oriented programming more clearer by creating a database class in PHP. This is what i have right now. I'm getting an error about $mysqli being an undefined variable when i try to call it using $db->query(); Please explain how to make the variable $mysqli defined. <?php class phpDatabaseClass ...

Calling methods reflectivly or using fixed methods with inheritance?

I'm working on a tiny web library and wonder wheter I should call the HTTP handler methods for GET, POST, PUT etc. reflectivly or not. Fixed Methods First the variant with an if else ... block calling methods given in the base class where they have a default implementation returning an error to the client. Since a request to an unsuppo...

PHP Objects Overwriting problem

Hello everybody, here's my problem: $Me[1] = new User(1); $Me[2] = new User(2); $Me[3] = new User(19); $Me[4] = new User(75); $Me[5] = new User(100); foreach ($Me as $k) echo $k->getId(); I'm trying to create 5 users with, of course, different ID. The problem is that the User with ID 2 'overwrite' the User with ID 1, the User with ID ...

Unable to resolve Javascript object method this reference

I've got a JS object I've made, with a few prototypal functions, and calling them from within the constructor is fine, using this.[function] But in a later event handler function, this refers to the element, and not the object, and I'm not sure how to resolve this: It goes through the AddListener fine, the mouse down event triggers, ca...