oop

What is "logger" in Java?

I have a class in which I see the following things: this.logger.severe(""); this.logger.warning(""); this.logger.info(""); I do not understand several things: How can we use a method that was not defined earlier? I mean, there are no "logger" methods defined in the class. I thought that these methods could be defined because the con...

When should I use "this" in a class?

I know that this refers to a current object. But I do not know when I really need to use it. For example, will be there any difference if I use x instead of this.x in some of the methods? May be x will refer to a variable which is local for the considered method? I mean variable which is seen only in this method. What about this.method(...

C++, vector of objects

In c++, is using a vector of objects a good idea? If not, what's wrong with this c++ code? #include <vector> using namespace std; class A {}; int main() { vector<A*> v ( new A); return 0; } from g++: 13: error: invalid conversion from A*' tounsigned int' ...

Writing to static classes in PHP

Assuming I have a Config class that I use to access the config vars from everywhere (Config::X). Is it possible to implement a function that can be called from outside the class that adds and/or modifies properties? Something like this is what I'm thinking of: class Config { const myVar = 'blah'; public static function write( ...

Should Model Objects Have Interfaces?

I am creating the domain model in my system. When designing my model objects, should I make interfaces for each entity object? People have told me that our web tier should not care about the implementation of an entity and we should be able to swap out implementations, but I'm not sure that would ever happen. For example, if we have a...

How to hide specific type completely using typedef?

I have a quick question about encapsulating specific types with typedef. Say I have a class Foo whose constructor takes a certain value, but I want to hide the specific type using typedef: class Foo { public: typedef boost::shared_ptr< std::vector<int> > value_type; Foo(value_type val) : val_(val) {} private: value_type val_; }...

How relevant are OO design patterns to web development in PHP?

Singelton, Decoratot, Abstract, Factory, and the list goes on. How relevant are OO design patterns in developing PHP applications for the web? Does it do anything for performance? Or is it just to keep code lean for agile development practices? Who is the major benefactor for implementing these design patterns? Is it the customer or the ...

Using inheritance purely to share common functionality

I recently encountered a situation in some code I am working on that doesn't make sense to me. A set of classes are inheriting from a base class purely to share some methods in the base class. There is no method overriding, just child classes calling methods from the parent class. It seems to me that this would be better modeled by ...

How should I declare a constant set visible for every instance of the class?

I would like to have a constant set in my class which would be visible for all instances of the class. First, I do not know if I need to declare it as "static". As far as I understand any changes of a static field (done by one of the instances) will be seen by other instances (so static variable is not bound to a specific instance). Mor...

Does having a method do more than one thing violate SRP?

For my purposes, I need to search for a specific node in an xml file and, if found, delete it. Should I pull search functionality out into its own method and delete functionality out into its own method? It seems more expensive to do it this way because I'll be searching the xml file once to see if it exists and searching it again to d...

friendly classes in c#

hey folks! actually i refactor some portion of code. what i want to do is to initialize an object "Task" with an object "TaskArgument". let s say "TaskArgument" is abstract and "Task" implements a method "OnEnterTask(TaskArgument args)" and is sealed (for some special behavior of the existing system, which is out of scope). old code: ...

How deep do you take the Has-a when it comes to Object Oriented Design?

If I say a car has a certain number of tires, a tire size, a tire brand, then I am guessing I could make a class like this: public class Car { public int TireCount {get;set;} public float TireSize {get;set;} public string TireBrand {get;set;} } On the other hand, I could make Tire a class and then make that a property of ...

Proper organization of public/protected/private functions in classes

Resharper (paired with StyleCop) has made me a bit of a neat freak when it comes to obeying most of its rules. One of the rulesets (I believe from StyleCop) enforces putting public functions first, then protected static, then protected, then private static, and finally private. The private functions are typically the ones backing up the...

What is a good standard exercise to learn the OO features of a language?

When I'm learning a new language, I often program some mathematical functions to get used to the control flow syntax. After that, I like to implement some sorting algorithms to get used to the array/list constructs. But I don't have a standard exercise for exploring the languages OO features. Does anyone have a stock exercise for this...

Parent Object in php

Hi guys, is there a way to traverse an object to get the parent object data? With "parent object" I don't mean the parent class, but literally object. Here an example, in a javascripty world :-) : $parent->test = "hello world!"; $parent->child = new B(); It would be great If I could access all the data from parent in the child obje...

How to create a platform ontop of CSLA? <-- if in case it make sense

Here is the scenario, I'm developing an application using csla 3.8 / c#.net, the application will have different modules. its like an ERP, it will have accounting, daily time record, recruitment etc as modules. Now the requirement is to check for common entities per module and build a "platform" (<- the boss calls it that way) from it....

Differences & Similarities Between Programming Paradigms

Hi Guys I've been working as a developer for the past 4 years, with the 4 years previous to that studying software development in college. In my 4 years in the industry I've done some work in VB6 (which was a joke), but most of it has been in C#/ASP.NET. During this time, I've moved from an "object-aware" procedural paradigm to an objec...

Having the option of customized classes but a unified class name

Suppose you are building a web application that is going to be a packaged product one day, one that users will want to be able to extend and customize. It comes with a core library consisting of PHP files containing classes: /library/ /library/frontend.class.php /library/filesystem.class.php /library/backend.class.php Now, suppose yo...

Modelling problem - Networked devices with commands

I encountered a head scratching modelling problem today: We are modelling a physical control system composed of Devices and NetworkDevices. Any example of a Device is a TV. An example of a NetworkDevice is an IR transceiver with Ethernet connection. As you can see, to be able to control the TV over the internet we must connect the Devi...

Migration from design to programming, AS3

I've got in over my head trying to learn programming, but love it. How would you teach a designer to migrate from design to object oriented programming? My interest is AS3 in Flash IDE, but any advice is welcome. Looking for a full explanation. THOUGHTS Designers learn differently Designers may need visual cues Designers may have di...