battle programmers alliance
Would you like to react to this message? Create an account in a few clicks or log in to continue.


battle programming a forum for elite programmers with extreme will power to sharpen their skills
 
HomeGallerySearchRegisterLog in
 

 upgraded Brain class is the best MVC software design pattern

Go down 
AuthorMessage
Moti Barski
super
super
Moti Barski

Posts : 565
Join date : 2011-08-02

upgraded Brain class is the best MVC software design pattern Empty
PostSubject: upgraded Brain class is the best MVC software design pattern   upgraded Brain class is the best MVC software design pattern EmptyMon Sep 13, 2021 7:36 am

Code:
class Brain(private val MVC: actionable, private val chi: thinkable) {
    fun doIt(ear: String, skin: String, eye: String) {
        val result = chi.think(ear!!, skin!!, eye!!)
        MVC.act(result)
    }
}

the class is constructed with an actionable and a ChobitV2 (thinkable)

example actionable :

Code:
import androidx.appcompat.app.AppCompatActivity;

import com.yotamarker.lgkotlinfull.LGCore.actionable;

import org.jetbrains.annotations.NotNull;

public class CerabellumV3 implements actionable {
    private MainActivity main;
    public CerabellumV3(MainActivity main) {
        this.main = main;
    }

    @Override
    public void act(@NotNull String thought) {
        main.toaster(thought);
    }
}

the chobit is the AI it processes the input and produces an output result.

the actionable (which is the MVC model) has access to the main classes hardware actions
such as SMS sending, robotics and so on.

depending on the chobit result you may want to engage on such hardware actions.

the actionable act function can be implemented to, for example, activate a public function to send an SMS
if the result is "some specific string".

on this example implementation the actionable simply uses some toast function I wrote on the main activity
to display the result as a toast message.

see MainActivity

Code:
package com.yotamarker.lgkotlinfull

import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.yotamarker.lgkotlinfull.LGCore.Brain
import com.yotamarker.lgkotlinfull.LGCore.ChobitV2
import com.yotamarker.lgkotlinfull.skills.Personality2
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
    var chii: ChobitV2? = null
    var brain: Brain?=null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        chii= ChobitV2(Personality2())
        brain= Brain(CerabellumV3(this),chii!!)
    }
    fun engage(view: View){
        //chii!!.doIt(editText.text.toString(),"","")
        brain!!.doIt(editText.text.toString(),"","")
        Toast.makeText(this, editText.text.toString(), Toast.LENGTH_SHORT).show()
    }
    public fun toaster(str:String){Toast.makeText(this, str, Toast.LENGTH_SHORT).show()}
}

this keeps the code much cleaner and the algorithmic logic can be used for other projects or even other programming languages

_________________
MB over and out emp it up
Back to top Go down
Moti Barski
super
super
Moti Barski

Posts : 565
Join date : 2011-08-02

upgraded Brain class is the best MVC software design pattern Empty
PostSubject: Re: upgraded Brain class is the best MVC software design pattern   upgraded Brain class is the best MVC software design pattern EmptyMon Sep 13, 2021 7:44 am

to keep code organizedmaxed any additional hardware related classes or files should be kept in a package (directory) called hardware

_________________
MB over and out emp it up
Back to top Go down
 
upgraded Brain class is the best MVC software design pattern
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
battle programmers alliance :: battle programming alliance :: the LivinGrimoire-
Jump to: