oop

Why use getters and setters?

What's the advantage of using getters and setters - that only get and set - instead of simply using public fields for those variables? If getters and setters are ever doing more than just the simple get/set, I can figure this one out very quickly, but I'm not 100% clear on how: public String foo; is any worse than: private String fo...

What could be the next evolution after OOP?

Today we can look back on the evolution of computer science and see structural programming, functional programming, and finally object-oriented programming. Additionally, things like meta-programming (reflective programming) and combining approaches into a single language (e.g. LINQ) are current. Another trend is template-meta-programmi...

Modeling A Book With With Ruby on Rails Active Record

Im modeling an online book with ruby on rails. The book has chapters, each chapter has pages. Modeling this part is easy. What id like to do is keep track of what pages each user has read and when and whether they liked that page / whether the user completed the book. How would one recommend modeling keeping track of this in rails? Id id...

trying to use only one method name

When I was programming a Form Validator in PHP, when creating new methods, I needed to increase the number of arguments in old methods. When I was learning Java, when I read that extends is to not touch previously tested, working code, I thought I shouldn't have increased the number of arguments in the old methods, but overridden the ol...

OOP - Sessions and PHP

Hi Folkes, iam a litte bit confused, i've started to learn php 5 the OO Way last year. First Projects are done with the Zend Framework. But some of my friends are talking about storing Objects in the $_SESSION Superglobal Array. But iam not able to find an good example, why or when this is nesecarry ? It would be great , if someone pe...

What is the official name of a class that must be inherited from to instantiate?

In OOP terms what is the name of a class that is always a parent, and the class cannot be used on its own, it can only be used if a class inherits from it. I don't need code samples, just the technical OOP term for this class, thanks! ...

Right design of my application - is inheritance right choice?

I have some simple scheduling of various events in my application and I used this class hierarchy: abstract class ScheduledEvent { public DateTime When{ get; set; } public abstract void Trigger(); } class WhateverEvent : ScheduledEvent { public override void Trigger(); } class AnotherEvent : ScheduledEvent { public overr...

OOD Layered Approach for ASP.NET/c# website

hi, I am writing ASP.NET website in which i break code into layer like form object class, Entity classes for business logic, Controller classes to control multiple entity class and finally data access classes. All above mentioned class have their saperate dll(s) because Form object an business classes are shred among multiple component...

Overloaded method selection based on the parameter's real type

Hi community, I'm experimenting with this code: interface Callee { public void foo(Object o); public void foo(String s); public void foo(Integer i); } class CalleeImpl implements Callee public void foo(Object o) { logger.debug("foo(Object o)"); } public void foo(String s) { logger.debug("foo(\"...

Question about object oriented design with Ruby

I'm thinking of writing a CLI Monopoly game in Ruby. This would be the first large project I've done in Ruby. Most of my experience in programming has been with functional programming languages like Clojure and Haskell and such. I understand Object Orientation pretty well, but I have no experience with designing object oriented programs....

Modifying state of other objects in a constructor: design no-no?

I'm refactoring some code and found this (simplified of course, but general idea): class Variable: def __init__(self): self.__constraints = [] def addConstraint(self, c): self.__constraints.append(c) class Constraint: def __init__(self, variables): for v in variables: v.addConstraint(sel...

Where should I be creating the entity objects?

I have an entity class and an entity DAO class. Should it be the responsibility of the DAO class to create instances of the entity class, or should there be an entity creator/manager class that uses the DAO class only to get the data from the database to create the entity class. Thanks, Chris ...

[C] OOP in C, implementation and a bug

Hi,I am trying to explore OOP in C. I am however a C n00b and would like to pick the brilliant brains of stackoverflow :) My code is below: #include <stdio.h> #include <stdlib.h> typedef struct speaker { void (*say)(char *msg); } speaker; void say(char *dest) { printf("%s",dest); } speaker* NewSpeaker() { speaker *s; s->sa...

What C# book would you suggest for C/C++ programmer?

I want to learn C# with standard libraries. For now I know C/C++ and basic OOP concepts. I would like to learn more complex OOP also. Is there any book which matches my needs? ...

OOP in C, inheritance, and bugs

I posted earlier (http://stackoverflow.com/questions/1574815/c-oop-in-c-implementation-and-a-bug/1574955#1574955) about my attempt with OOP in C, however as I'm still a new to C, there are a lot of gray areas that are resulting in code issues. I have since tried to implement inheritance, but now I'm getting a new errors, any help here? I...

Javascript: attaching OOP methods to events and the 'this' keyword

I am new to OOP Javascript and am having trouble with the this keyword and events. What I'm trying to achieve is: I have multiple DOM objects and want to not only bind a common event to them, but keep some data about the aforementioned objects in a global container (to increase runtime performance). So what I do is basically this: f...

3 tables, 3 classes, help designing my classes effectively

I have 3 database tables, all of them have the same 5 columns. They differ in that table#2 and table#3 each have another ID column in them. I don't want to create 3 seperate classes for this, but the problem is in my database helper class I have a method that loads the classes, like: public static LoadClass1(SqlDataReader reader) { ...

How to implement concept of .Net RIA Service (Single App Logic) in Asp.Net MVC?

First, let's see the following picture that explain the concept of .Net RIA Service. As you see, the application has app logic (business rule) that can be implemented both server side (databases + Repositories + external services) and client side (asp.net web page + Silverlight + WCF) Next, I create some data class that contains som...

changed object after storage or object-state used

Example: class UserStorage { public function addUser(User $user) { //saves to db } } class User { public function setName($name); } What if I add a user to the user storage and later change that user object? In this case you might argue that user objects only should be stored on __destruct. But sometimes this isn't an option ...

God object - decrease coupling to a 'master' object.

I have an object called Parameters that gets tossed from method to method down and up the call tree, across package boundaries. It has about fifty state variables. Each method might use one or two variables to control its output. I think this is a bad idea, beacuse I can't easily see what a method needs to function, or even what might h...