oop

Language-integrated design patterns

Hi. I've noticed that getting started with design patterns is pretty difficult for beginners. Understanding the design patterns structure requires a lot of time. Applying the design patterns to your practice requires a lot of time too. Agree, you can't see the differences between various types of the design patterns for the first time if...

UML arrows/pointers explanation

Hello, I have recently been studying UML and drawing simple diagrams with ordinary plain arrows between classes. But I know its not enought, there is plenty other arrows generalization, realization and etc which has meaning to the diagram reader. Maybe is there a nice resource which could explain each arrow(ordinary,plain, dotted, diamo...

Cakephp: Abstracting AppController another level, possible?

Hi All, I was wondering if it's somehow possible to add another abstraction controller between AppController and my app's other controllers? So that my controllers, e.g. UsersController extends SecureController and SecureController extends AppController. Also I want to be able to have other controllers extend AppController directly: So...

PHP: Does $_this have a special meaning?

I cant seem to find any documentation on what $_this means in PHP. It seems to be used quite a bit in the CakePHP framework. Any ideas? ...

C# - How to print objects in an array using for/foreach?

I have a homework assigment to iterate through an object array and print out these objects using for and foreach. I'm stuck on how to do that. Questions When you use a foreach loop, don't you have to declare the object? So the object declared in a foreach loop is null, because it doesn't call any constructors in my Employee class. Cod...

What happens when subclasses don't define a constructor in Java?

I have a few cases I wonder about. First, if you have no constructor: class NoCons { int x; } When I do new NoCons(), the default constructor gets called. What does it do exactly? Does it set x to 0, or does that happen elsewhere? What if I have this situation: class NoCons2 extends NoCons { int y; } What happens when I call new N...

Jump over parent constructor to call grandparent's

The problem is this: I have an abstract class that does some work in its constructor, and a set of child classes that implement the abstract class: class AbstractClass { AbstractClass(){ /* useful implementation */ } } class ConcreteClass1 extends AbstractClass { ConcreteClass1(){ super(); /* useful implementation */ } } Th...

Object Design Question User and Access Role in PHP with SQL

Hi, how do you design your objects lets say you have an object user and an object access_role. The user is stored in users table in an sql database, the access_role knows the user_id and is stored in an sql database. class user() { protected $_name; protected $_id; protected $_age; protected $_password; public...

How detailed should a object be?

I'm working on a kind of a HMI application and is creating objects to define a specific machine. Lets say this is a car for the sake of argument. A object for the engine is obvious. There are a few common sensors on the engine, and this is a few objects mounting to a few properties on the engine object. The throttle property is a input ...

PHP - MVC - Fetching the view

Greetings all! Looking for some help with MVC in a PHP context. Currently I am building a small, lightweight MVC framework to help expedite application development at work. It's a long hard separation eliminating inline code - at least with numerous projects looming overhead and the temptation to utilize it ever-present. I understand...

What is a covariant return type?

What is a covariant return type in Java? In object-oriented programming in general? I know, it's a "just Google it"; I did, and found the answer, but I'm asking anyways because of SO's goal to be the #1 Google result for programming questions. ...

Object-Oriented Execution

Consider the following source snippets: Snippet #1 StoredProcedure sp = new StoredProcedure( "PROC_NAME", getConnection() ); sp.putParameter( "ID", getId() ); sp.execute(); Snippet #2 StoredProcedure sp = new StoredProcedure( "PROC_NAME" ); sp.setConnection( getConnection() ); sp.putParameter( "ID", getId() ); sp.execu...

C++, oop, list of classes (class types) and creating instances of them

Hi, I have quite a lot of classes declared, all of them are inheriting from a base (kind of abstract) class ... so all of them have common methods I'd like to use ... now, I need to have a list of classes (not objects), later make instance of them in a loop and use the instances for calling mentioned common methods ... the pseudo-code...

Cross-platform OOP in C++

Of course, I know the best answer is "don't write your own cross-platform code, someone has already done what you need," but I'm doing this as a hobby/learning exercise and not in any paid capacity. Basically, I'm writing a smallish console application in C++, and I'd like to make it cross platform, dealing with things like files, socke...

PHP: Is it possible to retrieve the class name of a child class?

class Bob extends Person { //do some stuff } class Person { public function __construct() { //get the class name of the class that is extending this one //should be Bob } } How can I get the class name of Bob from inside the constructor of the Person class? ...

What is the point of defining Access Modifiers?

I understand the differences between them (at least in C#). I know the effects they have on the elements to which they are assigned. What I don't understand is why it is important to implement them - why not have everything Public? The material I read on the subject usually goes on about how classes and methods shouldn't have unnecessa...

How do I inspect a Class in Objective-C?

Update I fixed up the code to eliminate duplication of overridden methods and track originator of property or method by implementing Mark's suggestion. Haven't tackled property types yet (will probably start with property_getAttributes() when I do). Also stripped out vestigial underscores. Basically I need a way to remind myself what ...

class-table-mapper design php and ZF

Hi, is there a better way to work with ZF useing the mappers, real life objects and table_objects. This is how I do it with Zend Framework: class User_DbTable extends Zend_DB_Table_Abstract{ protected $_name = "user"; // name of the table } the user class -> user object: class User{ protected $_id; protected $_name; pr...

C++ efficient inheritence of certain methods in child classes

Hi, I find my self repeating a single line of code in child constructors, which are passed two variables. The first of these variables is always used to initiate a protected variable (defined in the parent class). I was wondering if there is a way for me to do that assignment in the parent constructor - which is then inherited, and do t...

List Types bypassing ReadOnly Properties?

When using custom classes with read-only properties that are of type List or similar (ie, ObservableCollection), it is still possible to 'get' the variable and call an Add() method on it to alter the content. Is there a way to stop this (without creating huge overloads of the List class) on 'external' access, or is it 'best practice' t...