oop

What is a better oo design scenario and why?

If I have a User and I want that user to Register, is it better to have a Registration class with a Register method that accepts a user or is it just good enough to have a User object that has a Register method public class Registration { public void Register(User user) { } } public class User { public void Register() ...

What is a ABSTRACT CLASS and INTERFACE and when would you use them in PHP?

What is a abstract class and interface in PHP and when would you use them? A layman answer with an example would be great to aid my understanding. Thank you in advance ;-) ...

Examples of practical javascript object oriented design patterns

What object oriented design patterns do you use in your application's javascript, and why? Feel free to post code, even if there is no formal design pattern attached to it. I have written plenty of javascript, but I have not applied much object orientated patterns to what I am doing, and I am sure i am missing a lot. ...

Javascript OO syntax

There seem to be many different ways of doing OO in JavaScript. I like: function ClassA(){}; ClassA.prototype={ someFunc:function(a,b,c){}, otherFunc:function(){} } var c=new ClassA(); and have never used features beyond what this provides (despite being a proficient OOer). I suspect this is old fashioned, because every so of...

How do I change the values of arrays from different classes?

How do I change the values of arrays from different classes? i've array in one class called creation all the array are global variable import addClass; public var first1:Array = new Array(); public var op:Array = new Array(); public var second:Array = new Array(); public var res:Array = ...

C# oops concept query

I have a question related to OOPS concept. I have a base class public class BaseClass { public int i = 10; public int x = 30; public string str = "Hello"; public virtual string Hello() { return "Hello of base class called"; } } I have a child class public class ChildClass : BaseClass { public int i = 20; ...

Is there a more modern, OO version of "Let's Build a Compiler"?

Is there a more modern, maybe object-oriented, equivalent to Jack Crenshaw's "Let's Build a Compiler" series? A while back I stumbled across "Let's Build a Compiler" and could just not resist writing some code. I wrote a recursive-descent C compiler in C# that output .NET CIL. "Write once, leak everywhere" was my slogan. Too bad I di...

How can I make this code Pythonic

So I have this code for an object. That object being a move you can make in a game of rock papers scissor. Now, the object needs to be both an integer (for matching a protocol) and a string for convenience of writing and viewing. class Move: def __init__(self, setMove): self.numToName = {0:"rock", 1:"paper",2:"scissors"} ...

Best approach when same condition needs to be checked at multiple places in code

Hi, Suppose you need to check some condition at multiple places in code. For ex. we have a configurable element in config file called System. So if System = "A" do some work/show some screen else do other stuff I dont think its a good idea to check at many places the same condition. what should be the approach ? Thanks. ...

Is it bad practice for a child object to have a pointer to its parent?

In a C++ application, let's say I have a window class, which has several instances of a control class. If my window wanted to notify a control that it had been clicked, I might use: control[n]->onClick(); Now let's say that the control needs to know the size of it's parent window, or some other information. For this I was considering ...

Practical example of Polymorphism

Can anyone please give me a real life, practical example of Polymorphism? My professor tells me the same old story I have heard always about the + operator. a+b = c and 2+2 = 4, so this is polymorphism. I really can't associate myself with such a definition, since I have read and re-read this in many books. What I need is a real world e...

PHP method chaining?

Hi, I am using PHP5, and heard of a new featured in object-oriented approach, called method chaining. Does any one know what it is? I want to know how to implement method chaining using PHP5 with object-oriented approach. Thanks ...

Is it ever necessary to define a method as "public"?

If all methods are public unless they are explicitly defined as something else, is it ever necessary to define a method as public? ...

Reasons to avoid access modifiers in php

hi, here's my question. What are valid reasons NOT to use keywords public, private, protected in php? The story: I've started a project with a team that actively uses access modifiers in their code (even "public" explicitly) and wants to convince me to do the same. I always find this kind of stuff totally useless in a dynamic language ...

When should private methods in PHP work on class variables, and when should such methods be used as functions?

Hi, I'm wondering when private/protected methods should work on the class it's variables (like $this->_results) and when such methods should be used as if they were functions (like $this->_method($results)). Examples below: Work on class properties <?php class TestA { protected $_results; public function getResults() { ...

The best way to interact with a database, with objects

Alright, so after years of feeling that I've been doing it the wrong way, what is the best way to interact with a MySQL database, using PHP. Going to start off small-scale, but eventually hoping to grow large scale. I'd love to be able to use objects, like such $book = new Book(1342); echo $book->title; So, what is the best way to go...

how do i solve this bad error

as you see this is a class create 4 text Fields , what i woona do is in this line of code first1[i].text = k1[i]; in the for loop to write the randomize numbers in the TextFields that's my code import flash.display.Sprite; import flash.display.DisplayObjectContainer; import flash.di...

java class/interface adapter question

I have a toughie I'm trying to wrap my head around. I have some public interfaces and some package-private classes as shown below. Basically my package private class (called UltraDecoder below) needs some grungy decode logic to decode data and perform some operations on it for its own internal use. However I would also like to make use...

C++ project layout

I am completely confused as to the proper way to layout a C++ project. I had all my classes in separate .cpp files, with their definitions in .h files. I then had one "header.h" which contained all the class headers, external dependencies and a few other things. But I wasn't able to use class names in the header files, where I needed to...

Redefinition of pure virtual methods in C++

Do you have to declare methods replacing a pure virtual function in a base class? If so, why? Because the base class has declared the methods as pure virtual, and therefore MUST exist in derived class, then is should not be necessary to redeclare them in the derived class before you can implement them outside of the class definition. Wou...