Let's say I'm implementing my own version of Scrabble.
I currently have a Board class that contains lots of Squares. A Square in turn is composed of a IBonus and a Piece. The bonus implementations are actually the usual bonus for Scrabble, but it is possible that I might try to add some new and twisted bonus to spice the game -- flexibil...
The only other language I've any experience with is Perl & this is my first crack at OO programming. I feel like I'm approaching this all wrong. One of the problems is probably me trying to code OO Java like I coded non-OO Perl. Can anyone suggest a way to gracefully accomplish what I'm trying to accomplish in the code snippet below? ...
I am doing the design of a small project where I didn't use programming against interfaces for all my classes. I found that some classes would hardly ever be needed to change, so I let them be referenced by their client classes as concrete classes.
So, let's say we have ClassB that'll be consumed be consumed by ClassA:
class ClassB {...
Hi i jut wanted to know that is the any specific difference between Abstraction and Encapsulation.Also is Abstraction the concept related to just OOPs or its a generic term.
...
Hi, I have previously asked this question and since I already accepted an answer, I thought I would ask another question separately.
http://stackoverflow.com/questions/3995673/recommended-program-structure
My query is: the different classes each have a lot of overlap but perhaps the odd boolean variable or string different - so I can s...
say I create someObj like this
var someObj = function(){
var self = this;
//use this normally
document.body.addEventListener('click',function(){
//use self because this is unavailable
},false)
}
new someObj();
In the event this is not the someObj which id like to use but in this case the body element. Is there a best prac...
This is a language agnostic question about object oriented design, particularly the passing of messages regarding object destruction. This whole question could just as easily use the terms Parent and Child instead of Factory and Item.
Which object should be responsible for an objects tear-down process; the object itself, or the factory...
First of all: A quite similar problem has been posted and somehow solved already, but is still not answering my specific problem. More about this later.
In words: I have a base class which provides some methods to all childs, but doesn't contain any property. My child is inheriting these methods, which should be used to access the child...
I'm not sure where to put some methods.
Let's say I want to send an email.
Which of the following options should I choose:
email = new Email("title", "adress", "body");
email.send();
or
email = new Email("title", "adress", "body");
Postman.send(email);
Because how can an email send itself? And isn't it better to have a central ob...
I've created 2 controllers in my Yii application: FirstController.php and SecondController.php in default controller path.
FirstController.php:
<?php
class FirstController extends Controller {
public static function returnFunc() { return 'OK'; }
}
SecondController.php:
<?php
class SecondController extends Controller {
public f...
This is quite a common problem I run into. Let's hear your solutions. I'm going to use an Employee-managing application as an example:-
We've got some entity classes, some of which implement a particular interface.
public interface IEmployee { ... }
public interface IRecievesBonus { int Amount { get; } }
public class Manager : IEmploye...
Let's assume I am in charge of developing a Scrabble game, being that one of the principal requirements of the client is the ability to later try out different ways and modes of the game. I already made a design that is flexible enough to support those kinds of changes. The only question left is what to expose to the client(objects' acce...
I have a question about righteous way of programming in Python... Maybe there can be several different opinions, but here it goes:
Let's say I have a class with a couple of private attributes and that I have implemented two getters/setters (not overloading __getattr__ and __setattr__, but in a more “Java-tistic” style):
class MyClass:
...
I'm going to use this opportunity to put down a number of related but different thoughts on object-oriented philosophy, as a sort of request for comments. If the admins see fit to close, I may make it a blog post instead. But I am asking questions, so I think it's a suitable community wiki.
Suppose I have an abstract class Bird. Supposi...
I'm learning OOP in Java, but I'm not sure how to implement this reference or whatever you want to call it.
There are two relevant classes: Manager and Team
Team contains a field called manager, which is an instance of Manager. This links the team to a manager. It also contains a String field called name, which is the teams name.
Mana...
I am puzzled why it won't display the name. I expect to see the output, "Jeffrey" but it doesn't. I created an object with an argument to be passed to the constructor so I expected "JEFFREY" to be displayed but it didn't. I added the echo function in constructor to see if it output jeffrey and it didn't echo either. PHP didn't show any e...
Is this is far as you would go regarding Object Oriented PHP or can i improve it further by putting HTML into a class? How would i go about doing that? Note: The code below is using a QuickForm by PEAR. Thanks in advance.
<?php
//MySQL class
require_once('database/class.mysql.php');
//Session class
require_once('sessi...
This particular variant of Nim involves:
Two players alternately take marbles from a pile. In each move, a player chooses how many marbles to take. The player must take at least one but at most half of the marbles. Then the other player takes a turn. The player who takes the last marbles loses.
I need to:
- Write a program in which a hum...
I have a class hierarchy representing different language constructs:
Expression <- NumericLiteral
UnaryExpression
BinaryExpression
IndexingExpression
IteratedExpression
...
The objects of these classes form complex tree hierarchies on which I have to perform va...
I have a class AllListener to encapsulate multiple Listeners as follows.
The problem is I have to write a loop in each event method(onStart(), onEnd()).
It's quite normal way in observer pattern code, but it's bad smell. Any better way to write loop once? Thank you!
class AllListener{
List<Listener> listeners;
void onStart(){
...