Describing nested classes in english - object-oriented-analysis

I am not sure I understand nested classes conceptually. A university class may have a student object inside it. That is composition. A university class may be a school, which is inheritance. But if I have a class defined within another class, how do I describe this relationship in a complete English statement? thanks.

A nested class is a member and as such has the same access rights as any other member.
Consider a Book which has properties like title, author, genre, year, publisher. Now publisher can be the inner class having properties like name, id, contact details etc.
Hope this helps

Related

Protege: how to connect two classes with a data property

I am trying to implement an ontology in Protege. I have a class Murder and a class Person. The class Murder is connected to class Person by two object properties that are:
hasCriminal --> domain Murder, range Person
hasVictim --> domain Murder, range Person
I would like to express that class Murder needs to have a Victim who is dead. So i put a data property of Person named dead of type boolean (yes or no).
How can I say in class Murder that the data property "dead" of Person should be put true?
Thanks in advance.

how to join equivalent classes from 2 different ontologies in Protegé?

I'm new in Protegé. I've created a new Ontology and I would like to merge the Person class with Person class in foaf.
How can I do that? I have tried with Equivalent to but I don't see both ontologies linked in http://www.visualdataweb.de/webvowl
Foaf and mine ontologies separated
I found the solution. I realized that Person class in my ontology is a subclass in foaf antology.
So, I've added as a subclass in Protegé and it worked :)

How does cakePHP naming convention work?

I'm relatively new to PHP. Started learning PHP, but then come across cakePHP, which is suppose to speed up development time.
After reading the documentation and blog tutorial I still don't understand the naming convention. I guess I won't know until I start to do some examples, but to get me started can someone please explain to me how cakePHP associate database tables to the controller/model layer?
The below code is an abstract from the tutorial. It is a controller method that passes the post id to the view layer. The database table is called "posts". $this->Post refers to the model class of Post, which correlates to the plural form of posts in the database.
public function view($id = null) {
$this->Post->id = $id;
$this->set('post', $this->Post->read());
}
OK I get that. Then, in the documentation it refers to the following correlation:
ReallyBigPerson and really_big_people
So it seems like the correlation actually follows the rule in English semantics. Does this mean that cakePHP has a list of singular and plural words hidden somewhere that it works from? For example can I use the below correlation without breaking the code?
This and these or Man and men or Foot and feet or Moose and moose or Goose and geese
Furthermore, if I have both singular and plural form of tables in my database, will it break the code, or will it just associate to the plural-formed table?
Just find it baffling... Why couldn't they just match the naming convention like for like with prefixes?
Inflector
CakePHP uses its Inflector class to determine the plurals of things.
Since the naming conventions dictate that model names are singular and tables names are pluralised, it uses the inflector to apply English semantics / rules to determine the plural.
If you need some help understanding the output of the Inflector, you can use the CakePHP inflector website.
Pluralisation Examples
Model name: Post
Table name: posts
Model name: User
Table name: users
Model name: Sheep
Table name: sheep
Model name: News
Table name: news
Model name: Radius
Table name: radii
Check the Inflector site to be sure.
Non-standard Table names
While CakePHP offers a standard rule set for naming and conventions, none of it is set in stone. If you want to change the name of the table used for a particular model, simply specify the table name in the model:
class Thing extends AppModel {
public $useTable = 'somethings';
}
Or, if you want a model that does not use a table:
class Post extends AppModel {
public $useTable = null;
}

How do I hard-code a type into my models in Django

Here's the logic for the models:
Category. There are several categories; each category can contain several products.
Product. There are several products; each product can only have one category.
Is it possible to specify what kind of category each product is within the model file itself? For example: can I set the model so that a shirt can only be clothing and nothing else?
Here's what I have so far (it doesn't validate):
class Category(models.Model):
CATEGORY_CHOICES = (
('CLOTHING', 'Clothing'),
('FURNITURE', 'Furniture'),
)
category = models.CharField(choices=CATEGORY_CHOICES)
class Shirt(Product):
category = models.ForeignKey(Category, default=CATEGORY_CHOICES.CLOTHING)
class Table(Product):
category = models.ForeignKey(Category, default=CATEGORY_CHOICES.FURNITURE)
I'm new at this. Thanks for the help!
You can validate your model on save with any arbitrary rules. So, write a validation rule that checks that all shirts are saved in the category clothing.
For user input, create a form that only provides choices corresponding to the product.
Good luck!
I suggest that you invest some time into adopting recently added model validation, while it's not automatic as forms validation (you'll have to call clean* methods yourself, probably inside save), you gonna get DRY validation that could be used on Model and Form level.
You can use callables to give instance as a default value
Something like this (untested code):
class Shirt(Product):
def getClothingInstance():
return Category.objects.get(category=Category.CATEGORY_CHOISES['CLOTHING'])
category = models.ForeignKey(Category, default=getClothingInstance)

DAO Best practices : Querying Parent / Children

Given you have a domain model with a simple parent / child relationship, and each entity has it's own associated DAO, eg:
Author
AuthorDAO
Book
BookDAO
If I want to add a DAO method for retrieving the books by a specific author, what's the best place for it?
class AuthorDAO
{
List<Book> getBooks(Author author);
}
or
class BookDAO
{
List<Book> getBooks(Author author)
}
I'd place a Book finder on the BookDAO. This is where I would expect it to be, regardless of its parameters. If you want to find a book, you don't want to scan all DAOs to find where the right finder is. Putting it somewhere else won't help the users of the API.
The BookDAO, because you want to get information about books. The Book is the main subject here.

Resources