oop

Object methods and stats - the best object oriented design approach question

Hi, I need to write some instance method, something like this (code in ruby): def foo_bar(param) foo(param) if some_condition do_bar(param) else do_baz(param) end end Method foo_bar is a public api. But I think, param variable here appears too many times. Maybe it would be better to create an private instance variable...

Problem 9 (Project Euler) with Java - is it perfect program?

I am new to Java and even OOP, but I tried to write program for this task: A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a^(2) + b^(2) = c^(2) For example, 3^(2) + 4^(2) = 9 + 16 = 25 = 5^(2). There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc. I want that y...

Prerequisite for learning to mock?

I watched a screen cast by the creator of Rhino Mocks in where he states something to the nature, you should not really get into mocking until you understand test driven development better and how to design code correctly, so my question is what are some resources for correctly designing/architecting code? ...

Python decorators compared to CLOS "around" method.

Hi, I'm reaching back to my CLOS (Common Lisp Object System) days for this abstract question. I'm augmenting the question to clarify: It appears to me that a Python decorator is sort of like an "around" method in CLOS. From what I remember, an "around" method in CLOS is a method/function that wraps around the primary method/functi...

Separation of Concerns when adding new types

I have a system I've been working on this week where I'm having a hard time balancing separation of concerns with easy extensibility. I'm adding new types to the system, and it feels like shotgun surgery. The basic idea is that data is collected (polled) from a remote system and then made available to a number of different kinds of cli...

good way to display db data the oop php way?

Im working on making a blog in oop php. Now Im trying to display the post entries in my db. I manage to output data from the created field but nothing else. Basically I have four fields in the post table in my db. I have created, author, title and body. With this code below I only manage to display created. Anyone got any clued to how I ...

OOP / Pattern: Customizing layout based on environment

I have an app that has subtle differences depending on where it's being viewed. Variations to business logic & view styles are fine - this is all handled through dependency injection & CSS respectively. However, where I'm coming unstuck is with small variations on view layout / elements. For example - if a user is running our applicat...

Eiffel: loosening the pre-conditions and tightening the post-conditions?

In Eiffel it is said that we should "loosen the pre-conditions and tightening the post-conditions", but I am not sure what this means. How does this benefit/is benefited by sub-classing? Thank you ...

__CONSTRUCT in PHP subclass

Hello, I have the following two classes. Settings: /* Settings */ class Settings{ function __CONSTRUCT(){ echo "Settings Construct"; } } /* PageManager */ class PageManager extends Settings{ function __CONSTRUCT(){ echo "PageManager Construct"; } } $page = new PageManager(); I thought that would work fine, but it only ru...

Using accessors: Good or bad?

I'm having a design issue I could use some advice on. Let's say we need (how original...) Employees in our new application. What I would normally do is something like this: public interface IEmployee { string EmployeeId { get; } string Name { get; } void Update(string newName, ...); ... } public class Employee : IEmploy...

Is it possible to further embed best practices into programming languages?

For example, in c# access modifiers implement information hiding by default (by giving classes and fields the most restrictive access possible by default). In ASP.NET you have app_code and app_data as libraries "built-in" in your web site. ASP.NET MVC takes it another step and "makes" you use MVC. I don't know how it is in different lang...

Insertion of classes in the inheritance tree

I wonder if it would be possible to insert classes in an inheritance tree at arbitrary positions. Example: class Base { public virtual void DoSomething() { Console.WriteLine("Base"); } } class D1:Base { public override void DoSomething() { base.DoSomething(); Console.WriteLine("D1"); } }...

Return code or out parameter?

I'm making a method to fetch a list of filenames from a server but I have come to a problem that I cannot answer. The method returns two things: an SftpResult which is an enum with a variety of return codes. the list of filenames. Of these three signatures: public static ArrayList GetFileList(string directory, out SftpResult resu...

Flex: how is loose coupling achieved by using interfaces?

Ive looked this up in a few different locations, but to be honest, i dont really get it. I get what loose coupling is, but not how interfaces in Flex would help to achieve it? ...

Objects which send themselves - a good idea?

Where do you draw the line when moving functions which operate on data into the class which contains that data? For example, imagine you have a simple class which stores a description of the weather, with variables for temperature, humidity, wind speed and direction, and the time at which the measurement was taken. Now imagine you have...

Method vs. function in case of simple function

Hi, I have original class (DownloadPage) and I need to add just one simple functionality (get_info). What is better approach in OOP? def get_info(page): # make simple function ... result = get_info(DownloadPage()) or class MyDownloadPage(DownloadPage): # make new class with inheritance def get_info(self): # w...

What's the best way to define the words "class" and "object" to someone who hasn't used them?

My neighbor is taking "Intro to Java", and asked me to help explain a few of the first-day concepts. I realized that since I do this everyday, I don't have the beginner's mind, and it's hard to relate some of this stuff from scratch. The one that's actually not trivial for me to explain is "what the heck is a class?" Best I have so f...

Forum with Php OOP

I learned PHP OOP basics and to improve my knowledge of that, I am willing to create forum from scratch using OOP. So, can you give me a few tips you think I should know, what classes should I use and etc to improve my OOP knowledge as much as it possible. Thanks. ...

How do I get non-global objects to interact from within a function?

I'm trying to create a Breakout clone using C++, and so have several objects (like ball, paddle, powerupicon, block, etc). I understand that it's bad practice to have them at global scope, so they're initialized inside main(). The problem comes in with needing to do stuff with those objects from inside other functions (like redraw(), or ...

whats difference between NoSql DB and OO Db?

whats difference between NoSql DB and OO Db? ...