oop

When should I start a method name that gets a property with the "get-" prefix?

What's a good rule of thumb for naming methods that return properties/attributes/members of an object? If an object has some immutable quality "blarg", should a method that returns that quality be called "blarg()" or "getBlarg()"? The Java API, for example, is inconsistent: most properties are accessed through "get" methods (even those...

Best OO practice to adapt one type to another?

I have a collection of domain objects that I need to convert into another type for use by the .NET framework. What is the best practice for doing such a transformation? Specifically, I have a type called ContentEntry and I need to convert it into a SyndicationItem for use in putting into a SyndicationFeed. The conversion itself is strai...

Encapsulation Principle

There's some object-oriented engineering principle that states something along the lines of "a class should only know about the contracts of the classes that it takes as arguments, or any internal ones it uses." The counter-example, in C++, is: Foo::bar( Baz* baz) { baz()->blargh()->pants()->soil(); // this is bad, Foo knows about b...

Overriding a member variable in C++

I have run into a bit of a tricky problem in some C++ code, which is most easily described using code. I have classes that are something like: class MyVarBase { } class MyVar : public MyVarBase { int Foo(); } class MyBase { public: MyBase(MyVarBase* v) : m_var(v) {} virtual MyVarBase* GetVar() { return m_var; } private: ...

How do you bring Denormalized Values Into your Business Objects?

I have two Tables. Order - With Columns OrderID, OrderStatusID OrderStatus - With Columns OrderStatusID, Description I have an Order Object which calls to the database and fills its properties for use in my code. Right now I have access to Order.OrderStatusID, but in my application I really need access to the "Description" field. How...

When should I use OO Perl?

Hi, All. I'm just learning Perl. When is it advisable to use OO Perl instead of non-OO Perl? My tendency would be to always prefer OO unless the project is just a code snippet of < 10 lines. TIA ...

Should I extend this class or just use it?

I am writing helper classes for a large project in PHP and I have written a class called Command. It is essentially an OOP wrapper around running system commands from PHP in a controlled way. It has methods like addOption() to add -a type options and addArgument() to add other arguments. I will need to do a lot of scp'ing of files aro...

More than 1 facade class in 'facade design pattern' ?

Hi all, Is it acceptable to make more than 1 facade class (not instance) in a facade design pattern? I mean, is it formally forbidden ? Will it inhibit the 'facade design pattern' advantage itself? ...

How does Python handle classes being in separate files or are they all supposed to be in one file

I'm working on framework for testing some command line utilities. I want to create some classes to hold the different types of information more easily. Python is fairly new to me so I'm not sure how you would handle this. Do you keep all your classes in one file with your main script or can you separate them into their own files and ...

Your personal, successful coding practices.

I've been thinking lately about a few practices that I have kind of adopted. Not things you see listed all the times, but patterns that you've looked back and said "I'm glad I did that", then adopted for yourself. I'm not really thinking of the ones you hear all the time, like "Refactoring" or any design patterns listed in common books...

Suggest chapters/topics for OOP Book

I am working on a nuts-and-bolts* book on object-oriented programming. The intent is to produce a short but practical tutorial and reference for the major concepts, pitfalls, practices, and promises of OOP while staying language-agnostic and steering clear of theoretical esoterica. Each chapter will be devoted to a single concept or top...

Object Oriented Design help from C++ to C#

Hey I usually run into a situation where I will create a class that should only be instantiated by one or a few classes. In this case I would make its constructor private and make it a friend class to the objects that should be able to instantiate it. For example (in C++): class CFoo { // private ctor because only a select few class...

How to dynamically call child class methods in PHP 5?

<?php class foo { //this class is always etended, and has some other methods that do utility work //and are never overrided public function init() { //what do to here to call bar->doSomething or baz->doSomething //depending on what class is actually instantiated? } function doSomething() { //...

What do you call a chart that illustrates class hierarchy?

Hi So I have a UML type chart that documents the classes and the hierarchy of a development. Just don't know what you'd call it? Any suggestions? ...

What does Method<ClassName> mean?

I've seen this syntax a couple times now, and it is beginning to worry me: for example: iCalendar iCal = new iCalendar(); Event evt = iCal.Create<Event>(); Google can't help, but I know SO can! ...

Help! Evil services are killing my objects...

When I believed in American dream about encapsulation and polymorphism, intrusion of Web Services washed my objects off with RPC calls... When I cherished my resurrected PONOs, ugly army of barbarians called proxy objects conquered my lands... Later, peace seemed to come back with DDD and NHibernate on the server side, but the SilverLi...

Selecting the Correct View for an Object Type

I've had this problem many times before, and I've never had a solution I felt good about. Let's say I have a Transaction base class and two derived classes AdjustmentTransaction and IssueTransaction. I have a list of transactions in the UI, and each transaction is of the concrete type AdjustmentTransaction or IssueTransaction. When I...

Recommendations on how to implement a validation class?

I am implementing a validation class in classic ASP. How should the validation class interface with my other classes? My current setup: The User class's set methods call the appropriate validation method in the validation class. Any errors that occur are stored in User.mError. For example, here's my set method for the Email member vari...

Virtualization in Super Class Constructor

I was of the opinion that virtualization doesnt work in the super class constructor as per the design of OOP. For example, consider the following C# code. using System; namespace Problem { public class BaseClass { public BaseClass() { Console.WriteLine("Hello, World!"); this.PrintRandom...

Interface inheritance: what do you think of this:

Hi When reviewing our codebase, I found an inheritance structure that resembles the following pattern: interface IBase { void Method1(); void Method2(); } interface IInterface2 : IBase { void Method3(); } class Class1 : IInterface2 { ... } class Class2 : IInterface2 { ... } class Class3 : IInterface2 { ... ...