I must be doing something wrong
public interface IActor
{
//actor stuff
}
public class BaseShip : IActor
{
//base ship stuff
}
public class PlayerShip: BaseShip
{
//Only the stuff for this particular ship
}
Why then doesn't this work:
IActor player = new PlayerShip();
Or
List<IActor> actors = new List<IActor>(){new P...
I have a base class that has an abstract getType() method. I want subclasses to be able to implement this method and provide the actual class to use.
In code, something like the following:
public abstract class A {
public static interface Tile;
protected abstract Class<Tile> getTileClass();
}
public class B extends A {
p...
In Java, it is very easy to code the following design:
public abstract class Pizza {
public static final Pizza.NULL = new Pizza() {
/* "null" implementations */
}
/* actual/abstract implmentations */
}
What is the preferred method to attain the same efficient scenario in Objective-C? I have been unable to find any...
I've overridden Equals and GetHashCode in an abstract base class to implement value equality based on an object's key property. My main purpose is to be able to use the Contains method on collections instead of Find or FirstOrDefault to check if an instance has already been added to a collection.
public abstract class Entity
{
publi...
In OOP, what is the difference between composition (denoted by filled diamond in UML) and association (denoted by empty diamond in UML) relationship between classes. I'm a bit confused. What is aggregation? Can I have a convincing real world example?
...
I wrote this yesterday, in a class Foo inheriting from Bar:
public override void AddItem(double a, int b)
{
//Code smell?
throw new NotImplementedException("This method not usable for Foo items");
}
Wondered subsequently if this is a possible indication that I should be using a Bar, rather than inheriting from it.
What other...
I am trying to become a good programming citizen through learning more about Dependency Injection / IoC and other best-practices methods. For this I have a project where I am trying to make the right choices and design everything in the "proper" way, whatever that might mean. Ninject, Moq and ASP.NET MVC help with testability and getting...
Following SRP and KISS principle I designed an object with properties only, but I need methods to work with the objects. What is the best way to separate entity object data and entity set object methods?
Currently I created the following objects:
Pet Entity object
Attribute Name
Attribute Age
Pet Entity Set object
List of Pet object...
I'm working in C# 2.0, but this would apply to most object oriented languages. When I create classes with public properties that wrap private fields, I switch back & forth between whether I should use the property or field internally. Of course C# 3.0 makes this easier with auto-properties, but it could still apply.
Does it matter?
pub...
I've had a hard time understanding the difference between composition and aggregation in UML. Can someone please offer me a good compare and contrast between them? I'd also love to learn to recognize the difference between them in code and/or to see a short software/code example.
Edit: Part of the reason why I ask is because of a revers...
I'm pretty new to OOP/OOD, and I realize I have a lot to learn, so I'd like to ask the SO community for their input.
Basically, I'm using CakePHP's MVC framework, and the online store I'm building is just using 2 models, Category and Product, described by the following CREATE statements:
CREATE TABLE `categories` (
`id` int(11) uns...
I've done a fair amount of work on MVC on the web, and we're learning about it in my OOP class. I'm seeing some differences, and I can't tell whether that's because the Web's version of the MVC pattern is different than the traditional one, or whether I misunderstood it.
From my understanding, The model (your flat files, RDBMS', etc) is...
I have the following classes:
class foo {
public void a() {
print("a");
}
public void b() {
a();
}
}
class bar extends foo {
public void a() {
print("overwritten a");
}
}
When I now call bar.b() I want it call the overwritten method a() in foo. It does, however, print "a".
...
I have this class where I am using a combination of jQuery and prototype:
var MyClass = Class.create({
initElements: function(sumEl) {
this.sumEl = sumEl;
sumEl.keyup(this.updateSumHandler);
},
updateSumHandler: function(event) {
// Throws error here: "this.updateSum is not a function"
this.updateSum();
},
updateSum: funct...
Every programmer ends up with a set of utility classes after a while. Some of them are true programming pearls and they are reused in several of your projects. For example, in java:
class Separator {
private String separator;
private boolean called;
public Separator(String aSeparator) {
separator =...
If I have this class:
<?php
class Model
{
var $db;
function Model()
{
$this->db=new Db_Class();
}
}
?>
and a second class that extended the parent class:
<?php
class LessonModel extends Model
{
public function LessonModel()
{
//code here
}
public function getTitle($id)
{
$...
Hi all,
I have a (design of) an application to basically work like this:
class Main, class BusinessLogic, class UserInterface
BusinessLogic and UserInterface are designed to be library-like - not on-goingly developed but used by a developer in say, class Main.
The constructor of BusinessLogic also instantiates UserInterface, which w...
I'm working in Delphi (and Delphi terminology), but my question is language neutral.
Suppose you have a class, TClient, which sends messages to another class, TFacade. I assume TClient instances would have a private reference variable of type TFacade. A method somewhere in TClient would create an instance of TFacade and assign it to th...
How does inheritance of NSNotificationCenter observers work? I have a parent class that several other classes end up subclassing. The parent class registers itself as an observer for a specific notification. I was under the impression that children would also be registered as observers as long as you invoke the super method where the reg...
Given a class that keeps a registry of its Objects:
class Person(object):
__registry = []
def __init__(self, name):
self.__registry.append(self)
self.name = name
How would I make the following code work (without using Person.__registry):
for personobject in Person:
print personobject
While researching I fou...