oop

Big class decomposition in Java

I have just started to learn Java and is curious is it any good practice in Java for good object decomposition? Let me describe a problem. In big software project it's always a big classes like 'core' or 'ui' that tends to have a lot of methods and are intended as a mediators between smaller classes. For example, if user clicks a button ...

Setting up a mock interface in C++

Hi.. I'm currently trying to use a certain SDK that has me loading functions off a DLL that a vendor provides.. I have to pass arguments to these functions and the DLL does all the work.. Now, the DLL is supposed to be communicating with another device, while I just wait for the results. However, I don't have this device, so how do I s...

When does it make sense to return this-reference?

Currently I can think of only three good reasons to return this in a (public) method, namely: (mmyers) when implementing fluent interfaces, e.g. public class X { ... public X enableValidation() { setValidation(true); return this; } ... } (Jon Skeet) for identity conversions, e.g. public class X { ... public X t...

Pitfalls for OO Programmer Learning the Functional Way?

I've been programming Java for a few years now, and I've dabbled in functional programming now and again. I'm thinking I should learn how to do the functional thing properly after having 'fun' with XQuery, so... Are there traps my OO way of thinking can lead me into when I'm writing in a functional way? ...

When to use Records Vs Objects

I use Delphi, but this is a question that I think is valid for any object-oriented programming language. When should I use records over objects. I used to think that you used records when you had some simple definition of a set of related data that you wanted to store together that didn't need to be able to manipulate itself. However e...

When should a class use its own getters/setters vs accessing the members directly?

When generating setters and getters in Eclipse one of the options is to use the getters and setters within the class rather than accessing the class members directly. Is this level of class internal encapsulation useful or is it taking a good idea one step too far? DUPE: http://stackoverflow.com/questions/476021/should-you-use-access...

Is there a heuristic to determine whether a method or field belongs in a class?

Is there a good rule of thumb or test I can perform to determine whether a method or field belongs in a class? How can identify when a member does not belong? I find that my single biggest stumbling block in object-oriented design is trying to figure out what goes where. It seems like there are far too many cases where the answer is: ...

VB.NET and OOP - Shared Methods and Base Properties

If you can't use Me. in a non-instance method, how would you use properties/functions from a base class in a Shared method? For example, ClassB inherits from ClassA ClassB has a Shared Method DoWork(); ClassA has a ReadOnly Property SecurityKey How do I … Public Sub DoWork() Dim test as String = Me.SecurityKey End Sub ...

Is this setter 'evil'

There's alot of talk about getters and setters being 'evil' and what not. My question is: is the following setter evil? (rest of class omitted for brevity's sake) int balance public void deposit(int amount) { this.balance += amount; } This class is emulating an ATM. In the UK there are a few ATM's that lets you deposit as ...

In Command/Query, how to get operation related messages back to the caller

Often when we're issuing commands or to querying our objects, there is extra information about the operation that we need to get back to the caller. E.g. bool IsSomethingOkayToDo() In this case, if false, we might want the caller to know why it wasn't okay to do. In C# typically I do: string reason; foo.IsSomethingOkayToDo(out reason...

How to go beyond callback programming?

I've noticed that a big part of my code is built around callbacks. Is this considered a "design flaw"? Are there better design patterns that I should follow? ...

What are the best practices for determining the tasks of Constructor, Initialization and Reset methods

This is a general OOP question although I am designing in Java. I'm not trying to solve a particular problem, just to think through some design principles. From my experience I have reached the habit segregating object setup into three phases. The goal is to minimize: extra work, obfuscated code and crippled extensibility. Construction...

Does n tier architecture break OO concept of encapsulation

I have an n tier application with presentation layer, business layer, DAL and business objects layer. Separating the objects and the operation written on the objects break the object oriented concept of encapsulation. ...

oo-spaghettio web architecture

I've noticed that the majority of enterprise web apps I've worked on over the past few years have seemingly mis-used the powers of oo. That is, what once would have been perhaps 1000 lines of HTML and script, has often now morphed into 10,000 lines of code, 50 classes, and 2000 method calls to do basically the same thing. I.e. oo and l...

How do I explain loose coupling and information hiding to a new programmer?

How do I explain loose coupling and information hiding to a new programmer? I have a programmer who I write designs for, but who can't seem to grasp the concepts of loose coupling and information hiding. I write designs with everything nicely broken down into classes by function (data access is separate, a class for requests, a contr...

How to get business objects and UI controls to talk to each other

I've got a person object with a name and age property that implements INotifyPropertyChanged. I want to hook this object up to an ASP.NET form so that the 'name' and 'age' properties bind to textboxes in a way that, when changes happen in either place (in the control or in the object) the other will get updated. Do I create an intermedi...

How to design a inherited collection

I'm writing a program in C# that has a custom collection. The custom collection performs some useful aggregate functions (AllSuccessful, %Successful, etc) over it's members which are of type ResultInfo. I have several classes that derive from ResultInfo (UploadResultInfo, XUploadResultInfo, and YUploadResultInfo), and would like to hav...

OOD: trouble identifying objects

This should be a simple one. Let's say I'm designing a very simple timeclock application. The user enters his ID, and the application shows him his hours for the week, hours for the day, and then allows him to punch in our out. It is smart enough to know whether an employee is currently punched in. No breaks or lunch or shifts or an...

Defining OOP for a new programmer.

In teaching a first language to someone with no programming background I am having a hard time defining OOP despite the fact that I prefer OOP, how can I define OOP to someone with little (or zero) programming experience? ...

How do I create an abstract base class in JavaScript?

Is it possible to simulate abstract base class in JavaScript? What is the most elegant way to do it? Say, I want to do something like: - var cat = new Animal('cat'); var dog = new Animal('dog'); cat.say(); dog.say(); It should output: 'bark', 'meow' ...