My program architecture

new topic     » topic index » view thread      » older message » newer message

This is my attempt to create program architecture - https://bubbl.us/?h=1a3a20/33eae6/17xOfr.DteIqY

Some notes: 1. The program is broken into pieces (for example, states of finite machine) in the least related to each other.
2. The logical part of the program switches between states. Main goal of the StateN: take the necessary information from the database and pass on.
3. Data is transferred to underlying function unchanged! Thus, the function can receive redundant information, but it does not matter, either for performance (after all, it's just a reference) or for dependability. In addition, it is easier to write unit tests.

Example of State:

include Data.e 
 
enum MAP, HERO 
 
export function State1() 
  sequence Map = getMap() 
  sequence Hero = getHero() 
  sequence State1Data = {Map, Hero} 
  return WhatHappendInState1(State1Data) 
end function 

Example of functions hierarchy:

include State1.e 
 
export function beginState1(sequence Data) 
  integer Health = getHealth(Data)  -- This function does not need a map, but gets it. 
  if Health <= 0 then  return STATE_DEATH  end if 
  sequence Map = Data[MAP] 
  Map = deleteHero(Map) 
  sequence WhatDoISee = observeMap(Data, Map) 
  if find(WOLF, WhatDoISee) != 0 then  return STATE_FIGHT  end if 
  if find(TREASURE, WhatDoISee) = 0 then  return chooseDirectionToGo(Data, WhatDoISee)  end if 
  return STATE_WON 
end function 
 
--------------------------- 
-- chooseDirectionToGo.e -- 
--------------------------- 
 
export function chooseDirectionToGo(sequence Data, sequence WhatDoISee) 
-- This function gets Data, despite the fact that they it would seem unnecessary. 
-- First, it may be needed by a complication of the algorithm. 
-- Second, the unit test itself can generate WhatDoISee from Data (it is more useful and universal). 
-- Third, underlying functions (called from current) may need Data. 
end function 

Perhaps I invented the bicycle. However, I found no such information, although read a few books on structured programming. Please comment and advice.

By the way, this thought came to my mind, that's when I remembered this game from my childhood. http://www.youtube.com/watch?v=vKcfOy5i_2Y

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu