Identifying a pattern -
while designing android application i've created classes related between them.
i sure kind of pattern/relationship popular , know more naming classes , learn more pattern (to improve design)
i have class, book, basic attributes: title, author , synopses.
the books stored in files, 1 file per book, , there class manage file operations load/save/delete. i've called class bookmanager.
the mainactivity has bookmanager operations ask available books, retrieve book, save modified book, etc...
what name of kind of relationship between objects?
your bookmanager seems data mapper, which, martin fowler wrote it, is:
the data mapper layer of software separates in-memory objects database. responsibility transfer data between 2 , isolate them each other. data mapper in-memory objects needn't know there's database present; need no sql interface code, , no knowledge of database schema. (the database schema ignorant of objects use it.) since it's form of mapper (473), data mapper unknown domain layer.
and mainactivity, activities in android more application controllers, martin fowler explains as:
a centralized point handling screen navigation , flow of application.
update:
about question
i did not know of data mapper. not similar mvc pattern?
the answer no, data mapper has nothing mvc. data mapper technically sql lives, , separates data retrieving process domain logic, instance, if need insert row table have method called save
or insert
, data mapper not care less how data been handled, processed or manipulated business logic, takes arguments passed , insert storage, in design, data mapper should not care type of dbms using,
example rudimentary code:
abstract class database implements somestroageinterfaces{ protected $host; protected $username; protected $password; protected $databasename; protected $isconnected; public function __construct($host, $username, $password, $databasename) { $this->host = $host; $this->username = $username; $this->password = $password; $this->databasename = $databasename; } abstract public function connect(); abstract public function createconnectionstring(); public function isconnected(){ return $this->isconnected; } } //concrete class example class mysql extends database{ public function connect($connectionstring = null) { if(is_null($connectionstring)){ //create connection string }else{ //connect using connection string } } public function select() { //some insert implementation; } public function from() { //some update implementati } /*some other implementations , abstract methods implementation too*/
so mapper like:
class testmapper{ private $dbh; public function __construct(database $dbh){ $this->dbh = $dbh; } public function selecttest($arg1){ $dbh->select($arg1)->from('tablename'); }
your data mapper here has no clue dbms using, selects $arg1
tablename
using $dbh
send it.
however, can use relevant object handle queries, main point is, storage interaction application done through data mapper.
note: syntax using php, , faster me write in java.
Comments
Post a Comment