Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LatticePoint:Eliminate redundant functional methods and simplify busi… #34

Open
wants to merge 99 commits into
base: master
Choose a base branch
from

Conversation

koust6u
Copy link

@koust6u koust6u commented May 16, 2023

…ness logic

Object Method: absoluteValue, killnegative, plus

Description: Change the name of 'absolueValue' to 'makePositive'.

Remove 'Killnegative', as it duplicates the functionality of 'absolueValue'.

Change the name of the 'plus' method to 'addThenAbsolute' and simplify the business logic.

Here is the documentation in English:

JS970 and others added 30 commits May 7, 2023 19:16
…ness logic

Object Method: absoluteValue, killnegative, plus

Description: Change the name of 'absolueValue' to 'makePositive'.

Remove 'Killnegative', as it duplicates the functionality of 'absolueValue'.

Change the name of the 'plus' method to 'addThenAbsolute' and simplify the business logic.

Here is the documentation in English:
Extract 3 detailed functions within a paint function: paintWater, paintFood, paintCells. By doing so, code readability can be increased.
… Template Method

Apply template method to SimulatedEvolutionCanvas. In SimulatedEvolutionCanavas it paint water, food, cells by paint function. Within the paint function there are three component function, paintCells, paintFood, paintCell. By apply template method to paint, developer can change painting algorithm or colors and so on. Therefore decompose it into two class, SimulatedEvolutionCanvas.java and ConcreteSimulatedEvolutionCanvas.java. Also SimulatedEvolution is generated in SimulatedEvolutionTab, changing code by generate ConcreteSimulatedEvolution instead of SimulatedEvolutionCanvas.
ConcreteGeneticInfo1.java created for Applying Template Method Pattern
See LifeCycle.java Commit for detail description of Template Method Pattern apply
Create GeneticInfo.java abstract class for apply template method pattern
Detail description of template method pattern apply is written at Lifecycle.java
Template Method Pattern was applied.

GeneticInfo.java is abstract class.

ConcreteGeneticInfo1.java is concrete class

Extensionability has been increased by applying template method pattern.

By now, this program does not violate OCP when test with different parameter
values (MAX_FAT, MAX_HUNGER, ... ).

And I declared four new variables at LifeCycle.java(AGE_INC, FAT_DEC,
HUNGER_INC, FAT_DIVISION) which used at move() method and havesex() method.

Those variables also help to not violate OCP when testing with other
bacteria(cell).
LifeCycle.java : Template Method Pattern
LatticePoint:Eliminate redundant functional methods and simplify busi…
Object Method: getNeighbourhoodFor
description:The method is a relationship that relies directly on a switch according to the laticeNeighbourhood type, so it encapsulates object generation using factory method patterns to increase code flexibility and prevent client code from relying on specific classes. When you apply a factory method pattern, passing a neighbor type creates an array of neighbor locations for that type and returns it.
Object method: getNeighbourhood

Description:  It involves extracting the repeated offsets into a separate array structure, making the code more concise and easier to manage. Instead of manually assigning the offsets for each neighbour point, the offsets are stored in a 2D array (offsets) where each row represents the x and y offsets for a specific neighbour point. By iterating over this array, we can calculate the new coordinates for each neighbour point in a more systematic and maintainable way
…nd Reusability

method: getVonNeumann, getWoehlke, getMoore
description: Refactored the code by extracting a separate method to eliminate code duplication and improve reusability. This promotes better code organization and maintenance by encapsulating common functionality in a reusable method.
Extracted repeating food generating while loop into generateFood() function.
PR: RatticeNeighbourhoodPosition: getNeighbourhoodFor
SimulatedEvolutionWorldLattice.java: Extract method
As Factory Method Pattern applied(CellCore - Abstract, CellCoreOriginal
- Concrete), Client class(Cell) create cellcore with createCellCore()
  method.
Factory Method Pattern applied for project's extendability and
flexibility.

Abstract class of Factory Method Pattern delegates object creation to subclasses.

CellCore class was originally concrete class that called from Cell
class.

After this commit, CellCore class is abstract class, and classes such as CellCoreOriginal creates concrete CellCore objects.

As applying Factory Method Pattern like this, project now have
extendability for new CellCore object which works different to
CellCoreOriginal
It was originally CellCore.java.

As Factory Method Pattern applied, it renamed to CellCoreOriginal(to
indicate it is the original logic of CellCore).

Factory Method Pattern was applied, so it's fine to add new CellCore class such
as CellCoreEvolution, CellCoreDegeneration which has different CellCore
logic.

And It satisfies OCP when it comes to add such new CellCore classes.
I made wrong declaration while applying Factory Method Pattern.

Concrete Class type couldn't be default type at Cell.java

I fiexd this error by changing Cell.java's field member type and Private Constructor's parameter type(CellCoreOriginal -> CellCore)
Refactored code for overall typo corrections and consistency, extracted
magic numbers for code coherence and improved security.
…/geometry/LatticeDimension.java

global: modification mistyping & add consistancy

Refactored code for overall typo corrections and consistency, extracted
magic numbers for code coherence.
Factory Method Pattern applied(Cell - Abstract, CellOriginal - Concrete).

Originally, Cell.java was concrete cell, but when it comes to implement new Cells that have different move or reproduction mechanism, Original code violate OCP.

So, I made Cell.java abstract class. And made CellOriginal.java extends Cell.java and  work exactly same way as Original Cell.java.

As a result, It doesn't make any violation of OCP when it comes to create new cells that have different features.
See commit(Cell.java : Factory Method Pattern) for detail.

CellOriginal.java is product class of Factory Method Pattern.

It was Originally worked as Cell.java before refactoring, but now it's concrete logic is implemented at here.

Duplicated functions were remain at Cell.java. And Changeable features were implemented at concreteCell(like this - CellOriginal.java).
See commit(Cell.java : Factory Method Pattern)for detail.

As SimulatedEvolutionModel.java is the client class of Factory Method Pattern, it initializes type `Cell` with concrete `CellOriginal`.
koust6u and others added 30 commits June 5, 2023 09:02
Junit4 Dependiency Configuration
GeneticInfoTest perform unit test for all methods of GeneticInfo class, using concrete parameters at ConcreteGeneticInfo1.
It checks the range of parameters. If parameter value is out of given range, assertion occers.
Class coverage: 100%
Method coverage: 80%
Line coverage: 85%

IntelliJ coverage coverage 측정은 본 프로젝트에서 구현 하지 않는 Object
Type 의 내장 method toString, hash 등과같은 것도 같이 포함하여 측정하기
때문에 실제 구현 method에 대한 coverage는 100%지만 80%로 감소하여
측정되는것으로 생각됨.
GeneticInfoTest.java : Junit Test for GeneticInfo class
LatticeDimension: unit test code for LatticeDimension.java
…LifeCycle class

Function move() unit test under LifeCycle Class.
Function haveSex() unit test under LifeCycle Class.
Function isYoungAndFat() unit test under LifeCycle class
Function isPregnant() unit test under LifeCycle class.
Function idDead() unit test under LifeCycle class.
Function eat() unit test under LifeCycle class.
Function isYoung unit test under LifeCycle class.
Function isAdult() unit test under Lifecycle class.
Function isOld() unit test under LifeCycle class.
Function isHungry() unit test under LifeCycle class.
Function getLifeCycleStatus() unit test under LifeCycle class.
- Packed following files into LifeCycleTest package
	- LifeCycleTest_eat.java
	- LifeCycleTest_getLifeCycleStatus.java
	- LifeCycleTest_haveSex.java
	- LifeCycleTest_isAdult.java
	- LifeCycleTest_isDead.java
	- LifeCycleTest_isHungry.java
	- LifeCycleTest_isOld.java
	- LifeCycleTest_isPregnant.java
	- LifeCycleTest_isYoung.java
	- LifeCycleTest_isYoungAndFat.java
	- LifeCycleTest_move.java
LifeCycleTest : package for LifeCycle Junit test.
Testing function 'getValueByStatus' by putting each 7 LifeCyclestatus.
Testing function getZoom.
Testing function getters.
CensusCanvas.java : Junit test for Method in CensusCanvas
Testing 7 CensusStatus classes which implement CensusCellStatus.
Testing countStutus, getColor, getColorForeground, getColorBackground,
getCellNumber().
Also fix remained name "fullAgeCells" to "adultCells" in
SimulatedEvolutionPopulationCensus.java file.
Censusstatus package : Junit Test for CensusStatus class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants