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 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 ;-)
...
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.
...
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?
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 = ...
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, 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...
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"}
...
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.
...
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 ...
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...
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
...
If all methods are public unless they are explicitly defined as something else, is it ever necessary to define a method as public?
...
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 ...
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()
{
...
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...
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...
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...
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...
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...