Тимофей Даньшин wrote:

Is it a good idea to split all those classes into categories for writing, reading and testing? For example, Database (Writing), Database(Reading), Database(Testing) and so on? Or is it a silly thing to do for some reason?


I suggest reading about why Objective-C has categories. Here's one simple description. You can probably google others.

  http://en.wikipedia.org/wiki/Objective-C#Categories

To me, the real question to ask isn't "Should I use categories?", it should be "What categories should I use?". That is, what does your most basic class represent ("Database" might be too large a concept to represent well), and what functionality resides in that most basic representation? Then what are the related groups of functionality that are added to that basic representation? Then which of those are best done as categories, which as subclasses, and which as formal protocols?

If you're asking "Should I use categories?", then it seems likely the problem hasn't been broken down far enough yet. Once that breaking down occurs, then classes, protocols, and categories will tend to become apparent as a natural consequence of how you break the problem down in order to reach a desired solution. Breaking problems down, and doing it well, can be the hardest part of reaching a solution.

Elaborating a little on the parenthetical ("Database" might be too large a concept to represent well), consider how Java works with SQL databases. It has the JDBC classes and interfaces, and there isn't a "Database" class anywhere among them. Instead, there are Connection's, various Metadata's, Statement's, and ResultSets. All are abstract interfaces (equivalent to Obj-C formal protocol). The concept of "a database" is only implied, in that a Connection to "a database" is created from a URL and other things, and is supported by a Driver for the DBMS product being connected to.

This is not meant to suggest JDBC is the best or only way to create a database interface. It's just to illustrate that creating a class Database and a category Reading, which don't naturally emerge from breaking the problem down, could be a poor way to solve the problem.

  -- GG





Subject: Categories and splitting an app into logical blocks.
From: Тимофей Даньшин <em...@hidden>
Date: Fri, 15 May 2009 23:57:07 +0400
Delivered-to: em...@hidden
Delivered-to: em...@hidden
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message- id:from:to :content-type:content-transfer-encoding:mime- version:subject:date :x-mailer; bh=66jF3T1j75fcJSass7p/mI5Q7w7vd/ B7FuIsSNgVmxc=; b=rmasGDuAAFk2vi449YDIojomPxWXFpLbqO/uA +Z11y58Db8s78YXK0TgEQD60JHBrE vUcSBDNrXvxRSKdLs5pApehj7ut5rTz5ZFoPKzYH3wZkWeprotHM6db0YLcdML2ZyP1S 8GIAMFSkJn6M8haWXr5DaMduk5c/lesPBOq5c= Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:from:to:content-type:content-transfer-encoding :mime- version:subject:date:x-mailer; b=t2C+yRMFbSKgm5JDm0r5V7y7r3We15U81 +AgB6NMRfdcq1bh1FBFxZWE3yNooDX7b6 g54iz1wu4dvo8t44FYC2J/xAJSyCugq/ puWNyHQntb+kqU9wWGf7ouOR8Iy2VYlwmgUY TCBBv/ xHIf6hzHMl2mO06zfwPy0PaErn3Nbik=


Hello.

Suppose, I have an app that, for example, works with a database. It can write to the db, it can select things. There is a class that works with the database, a class that controls that class and a class that interacts with the gui. And, of course, there is some testing code in all the three "layers".

Is it a good idea to split all those classes into categories for writing, reading and testing? For example, Database (Writing), Database(Reading), Database(Testing) and so on? Or is it a silly thing to do for some reason?

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to