oop

c++ global functions and OOP?

In C++ one can have a 'GLOBAL FUNCTION', which means it does not belong to any class. I wondered if that isn't just a violation of the basic principles of OOP? What would be the difference with using a global function or function that is static in a class? I'm thinking the latter is more OOP oriented. But I may be wrong however... D...

Type or Vector for representing points\positions

Hi Folks, I have a series of points\positions that won't change. Should I represent as Vector of ints or as a new type? My preference at the moment is to go with vector: doSomething(myVec[0], myVec[1] ); doSomethingElse(myVec[2], myVec[3] ); as opposed to: doSomething( myType.getPos1(), myType.getPos2() ); doSomethingElse( myTyp...

Using Objects throughout application

Hi I have one page where I set up an object of class User. $id = $_SESSION['user_id']; $current_user = new User(); $current_user->getFromID($id); I've tried accessing this object from another page but it comes up blank. Is there any special way to do this? ...

Multiple Objects of the same class in Python

Hello, I have a bunch of Objects from the same Class in Python. I've decided to put each object in a different file since it's easier to manage them (If I plan to add more objects or edit them individually) However, I'm not sure how to run through all of them, they are in another Package So if I look at Netbeans I have TopLevel... an...

C++ Constructor Parameters Question

Hi, I'm learning C++. I have a simple class named GameContext: class GameContext { public: GameContext(World world); virtual ~GameContext(); }; To initialize a GameContext object, I need a World object. Should the GameContext constructur take a pointer to a World object (World*), the address to a World object (&...

If class inherited many times can be slower ?

When i try to create good object hierarchy which will help to write less code and avoid to use unnecessary fields ,i feel myself free to create many base classes for good grouping which is usually abstract. What can be disadvantage of doing it like that ? Many times inherited class can be slower ? To see many unnecessary abstract classe...

Are there any "gotchas" to watch for in using a Class (object) within itself?

I've got a Registry class and there are a few Registry values that I want to access from within that Registry class. (There is a bit of a calculation with these values so I thought I'd just put all that code right in the Registry Class itself). So we might have something within our RegistryRoutine.cls like: Function GetMyValue() as int...

How to design around type covariance error

How to correct this design. Error because C# doesn't allow Type Covariance. How can I improve or correct this design public interface ITimeEvent { } public interface IJobTimeEvent : ITimeEvent { } public interface IActivityTimeEvent : ITimeEvent { } public interface IAssignmentTimeEvent<T> where T...

Questions while designing OOP hierarchy

Hello When creating inheritance hierarchy, i get confused .Abstract Base class should contain only commonly used stuffs for inherited classes.But knowing which is commonly used methods,fields and properties is not possible while designing.So i feel free myself to grouping them with abstract classes which inherits hierarchicaly. This is ...

Repository, Service or Domain object - where does logic belong?

Take this simple, contrived example: UserRepository.GetAllUsers(); UserRepository.GetUserById(); Inevitably, I will have more complex "queries", such as: //returns users where active=true, deleted=false, and confirmed = true GetActiveUsers(); I'm having trouble determining where the responsibility of the repository ends. GetActiveU...

Should I put actors in the Domain-Model/Class-Diagram?

When designing both the domain-model and class-diagrams I am having some trouble understanding what to put in them. I'll give an example of what I mean: I am doing a vacations scheduler program, that has an Administrator and End-Users. The Administrator does a couple of things like registering End-Users in the program, changing their p...

Is OOP based on any branch of mathematics?

I know relational databases are based on set-theory, functional programming is based on lambda calculus, logic programming is based on logic (of course :)), and now that I think of it; I'm not sure if imperative and generic programming is based on any particular branch of mathematics either. ...

Is the a pattern for iterating over lists held by a class (dynamicly typed OO languages)

If I have a class that holds one or several lists, is it better to allow other classes to fetch those lists (with a getter)? Or to implement a doXyzList/eachXyzList type method for that list, passing a function and call that function on each element of the list contained by that object? I wrote a program that did a ton of this and I hat...

Asynchronous request management application design

I have a daemon which exposes RMI interface for submission of various potentially long running bulk operations. The daemon may also talk to workflow/BPM system as a part of request processing. This essentially means that the request processing (post submission) also has an asynchronous component to deal with; which probably would require...

Sharing class member data between sub components

I have an aggregate 'main' class which contains some data which I wish to share. The main class also has other class members. I want to share the data with these other class members. What is the correct / neatest way to do this? The specific example I have is as follows. The main class is a .net Form. I have some controls (actually c...

PHP OOP problem

Hello <?php class Templater { var $params = array(); public static function assign($name, $value) { $this->params[] = array($name => $value); } public static dunction draw() { return $this->params; } } <?php $test = Templater::assign('key', 'value')->draw(); print_r($test); I nee...

Dealloc on my custom objective-C

Hello. I'm developing an iPhone application, and I very new on iPhone development. I've created some custom classes with instance variables (NSArray, NSString, etc.). All classes inherits from NSObject. Should I create a dealloc method to release all instance variables? Thank you. ...

Inheritance question / problem

I'm creating a custom Layout for android. The layout implementation is exactly the same, but once I need to extend from RelativeLayout, and once from LinearLayout. class Layout1 extends LinearLayout { // methods and fields } class Layout2 extends RelativeLayout { // the same EXACT methods and fields } How can I use inheritance to avo...

Does this pattern have a name?

Disclaimer: I'm trying to learn proper OO programming/design, so I'm pretty new to this stuff. I guess this is a general design patterns question, but I'll base my example on a game engine or something that renders objects to the display. Consider the following: How can this sort of separation between physical objects (e.g., cubes,...

Checking method visibility in PHP

Is there any way of checking if a class method has been declared as private or public? I'm working on a controller where the url is mapped to methods in the class, and I only want to trigger the methods if they are defined as public. ...